webpack HtmlWebpackPlugin 插件如何忽略jsp标签?

  1. webpack配置
new HtmlWebpackPlugin({
      inject: true,
      minify: {
        ignoreCustomFragments: [ /\${[a-zA-Z]*?}/],
      },
      template: paths.appHtml
    }),
  1. html
<script>
    var a="${a}";
    var b="${b}";
</script>
  1. 报错
Template execution failed: ReferenceError: a is not defined
  1. 请问要怎么配置才能够让插件忽略${}
阅读 4.2k
2 个回答

看看这个文档: https://github.com/jantimon/h...

如果不指定模板引擎,默认使用 ejs 模板解析。

However this also means that in the following example webpack will use the html loader for your template. This will cause html minification and it will also disable the ejs fallback loader.

所以你需要强制使用 html 而禁用掉 ejs。

{
  module: {
    loaders: [
      {
        test: /\.html$/,
        loader: 'html-loader'
      }],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    })
  ]
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题