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

查看:785
本文介绍了javascript - 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. 请问要怎么配置才能够让插件忽略${}

解决方案

看看这个文档: 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'
    })
  ]
}

这篇关于javascript - webpack HtmlWebpackPlugin 插件如何忽略jsp标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆