我有一个使用html-webpack-plugin和webpack的问题,其中html-webpack-plugin正在将脚本注入到index.html
的主体中。这显然会导致webpack不断刷新,并且每次都会生成新文件。首先,我如何防止这种情况发生,其次,有没有办法配置html-webpack-plugin来删除相应于不再存在的webpack生成的javascript文件的脚本(在这种情况下,过时的文件是相应的在下面的配置文件中输出static/bundle-[hash].js
)?html-webpack插件注入和webpack导致持续刷新
这里是的WebPack配置文件:
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: "./js/main.js",
output: {
filename: "static/bundle-[hash].js",
},
resolveLoader: {
moduleExtensions: ['-loader']
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-0']
}
},
{
test: /\.css$/,
loader: 'style-loader',
},
{
test: /\.css$/,
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}
]
},
plugins: [
new CleanWebpackPlugin(['static/bundle*.js']),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: 'body'
})
]
};