为什么不能将HMR和chunkhash一起使用?

时间:2018-07-26 07:53:21

标签: webpack webpack-hmr

我知道在webpack.config.js中HMR插件和chunkhash不能一起使用。但是我不知道为什么。有人可以帮我解释一下吗?

错误的代码是:

const webpack = require("webpack");
const HtmlWebpackPlugin =  require("html-webpack-plugin");

module.exports = {
    devtool: "eval-source-map",
    entry: __dirname + "/app/main.js",
    output: {
        path: __dirname + "/build",
        filename: "bundle-[chunkhash].js"//改为“bundle.js”及为正确的代码
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: __dirname + "/app/index.tmp1.html"
        }),
        new webpack.HotModuleReplacementPlugin(),
    ],
}

1 个答案:

答案 0 :(得分:0)

使用HMR,该块将保存在内存中,而不会发射到磁盘。确实没有理由进行哈希处理。现在,当您转到生产环境时,您希望该哈希值用于缓存清除。签出Paragons。它使用的是HMR,在Webpack config中您可以看到它的处理方式:

filename: devMode ? '[name].js' : '[name].[hash].js',
chunkFilename: devMode ? '[name].js' : '[name].[chunkhash].js',
相关问题