2017-05-13 56 views
0

我想使用此模塊https://www.npmjs.com/package/html-minifier如何使用html-minifier npm模塊?

node.js的再壓縮我的HTML文件,我有這樣的代碼

   // minify the html code 
       fse.readFile(filename, function(err, data) { 
        if (err) return console.error(err); 
        var result = minify(data.toString(), { 
         removeAttributeQuotes: false 
        }); 
        console.log(result); 
       }); 

但是它記錄相同的代碼從原來的文件。它沒有縮小它。有誰知道什麼是錯的?

謝謝

回答

2

幾乎所有的html-minifier選項在默認情況下都是禁用的。

嘗試用一些options

{ 
    collapseWhitespace: true, 
    removeComments: true, 
    removeEmptyAttributes: true, 
    removeRedundantAttributes: true, 
    removeScriptTypeAttributes: true, 
    removeStyleLinkTypeAttributes: true 
}