我有一個使用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'
})
]
};