2016-04-12 67 views
0

我使用html-webpack-plugin來使用webpack縮小html文件。html-webpack-plugin生成冗餘標籤

原始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

文件'該插件會爲你生成一個HTML5文件,其中包括使用腳本tags'體內所有的WebPack包。因此,您可以從模板中移除'''。 –

+0

非常感謝你!這解決了問題。 – tet

回答

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