webpackstripblocks

html-webpack-plugin with webpack-strip-blocks – Stack Overflow


I want to strip out a section of code before html webpack plugin loads the file.

In webpack.config.js rules section, I have

[ ...otherrules,
  {
    test: /.html$/,
    enforce: 'pre',
    use: [{
      loader: 'webpack-strip-blocks',
      options: {
        blocks: blocks,
        start: '<!--',
        end: '-->'
      }
    }]
  },
  ...evenMoreOtherRules
]

and in the plugins section

plugins: [
      new HtmlWebpackPlugin({
        template: path.resolve(__dirname, './app/index.html'),
        filename: 'index.html',
        inject: 'body'
      }),
      ...otherPlugins
]

When I try running it I am getting

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>



لینک منبع