var path = require("path");
module.exports = {
// mode: "development || "production",
entry: {
main: "./example"
},
optimization: {
runtimeChunk: true
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].[chunkhash].js",
chunkFilename: "[name].[chunkhash].js"
}
};
webpack的runtime代码会在entry的chunk文件里,所以加上chunkhash并不能起到浏览器缓存的效果,因为每次打包即使entry代码没有变,chunkhash也是会变的。所以将webpack的runtime代码单独打包为一个文件即可解决。需要设置
optimization: {
runtimeChunk: true
}
然后output里filename 和 chunkFilename加上[chunkhash] 。