带webpack-strip-blocks的html-webpack-plugin

时间:2018-02-14 00:44:49

标签: webpack webpack-2 html-webpack-plugin

我想在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>

0 个答案:

没有答案