html-webpack-plugin生成冗余标记

时间:2016-04-12 10:29:05

标签: webpack html-webpack-plugin

我使用html-webpack-plugin来使用webpack缩小html文件。

原始html文件只有<script src="./app.js"></script>,但在使用html-webpack-plugin缩小文件后,它会生成<script src="./app.js"></script><script src="app.js"></script>。 它会插入一个冗余的<script src="app.js"></script>。 我已尝试html-minifier提供的所有选项,但尚未解决问题。

有谁知道如何解决这个问题?

我的webpack配置的一部分:

new HtmlWebpackPlugin({
    template: 'app/main.html',
    filename: 'index.html',
    minify: {
      collapseWhitespace: true,
      removeComments: true,
      removeRedundantAttributes: true,
      removeScriptTypeAttributes: true,
      removeStyleLinkTypeAttributes: true,
    },
  }),

1 个答案:

答案 0 :(得分:0)

插件中有一个选项。您可以将其设置为false并自行编写,也可以将其设置为true等,并从html中删除行。

inject: false // "body", "head"

更多信息:

inject  {Boolean|String}    true    true || 'head' || 'body' || false Inject all assets into the given template or templateContent. When passing true or 'body' all javascript resources will be placed at the bottom of the body element. 'head' will place the scripts in the head element
相关问题