1

运行 Webpack Dev Server 时,它会创建哈希文件,但不会创建真正的物理文件 - 所以会出现 404 错误但是如果使用 Watcher 运行 Builder,它会创建真正的哈希文件,我可以直接从服务器获取它

但是:HMR 说 Get different Hash 然后由 Builder 创建

SO:我有一个真正的哈希包,可以从http://localhost:8000/获取...,但我的浏览器想要获取资源文件夹中不存在的另一个哈希包

raven.js:1074 GET http://localhost:8080/004e386432676c218bd0.hot-update.json 404 (Not Found)

奇怪的事情:下一个字符串显示了两次

2 raven.js:80 [WDS] App updated. Recompiling... -> 两次

配置如下:

var buildPath = __dirname + '/public/js/bundles';
module.exports = {
    context: path.join(__dirname, '/resources/scripts'),
    devtool: process.env.NODE_ENV === 'production' ? null : 'inline-source-map',
    entry: {
        ...entries...
        campaigns: [
            'webpack/hot/only-dev-server',
            'webpack-dev-server/client?http://localhost:8080',
            './appjs/campaigns/campaignsEntry.js',
        ]
    },
    output: {
        path: buildPath,
        publicPath: 'http://localhost:8080/',
        filename: process.env.NODE_ENV === 'production' ? '[name]-bundle-[chunkhash].js' : '[name]-bundle.js'
    },
    devServer: {
        hot: true,
        contentBase: buildPath,
        publicPath: 'http://localhost:8080',
        port: 8080,
        headers: { "Access-Control-Allow-Origin": "*" },
        lazy: false,
        stats: { colors: true }
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015-loose', 'react'],
                    plugins: ['transform-object-rest-spread', 'transform-class-properties']
                }
            }
        ]
    },
    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
        }),
        new webpack.optimize.OccurrenceOrderPlugin(),
    ]
};
if (process.env.NODE_ENV === 'production') {
...
} else {
    module.exports.plugins.push(
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin()
    );
}
4

0 回答 0