我想在html webpack插件加载文件之前删除一段代码。
在webpack.config.js规则部分,我有
[ ...otherrules,
{
test: /\.html$/,
enforce: 'pre',
use: [{
loader: 'webpack-strip-blocks',
options: {
blocks: blocks,
start: '<!--',
end: '-->'
}
}]
},
...evenMoreOtherRules
]
并在插件部分
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './app/index.html'),
filename: 'index.html',
inject: 'body'
}),
...otherPlugins
]
当我尝试运行它时,我得到了
ERROR in ./~/html-webpack-plugin/lib/loader.js!./app/index.html
Module parse failed: /Users/neolivz/Work/neolivz/node_modules/html-webpack-plugin/lib/loader.js!/Users/neolivz/Work/neolivz/node_modules/webpack-strip-blocks/index.js??ref--7-0!/Users/neolivz/Work/neolivz/app/index.html Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <!DOCTYPE html>
| <html>
| <head>