下面我們介紹一下該插件的配置項。查看源碼我們會發現如下代碼。
this.options = _.extend({
template: path.join(__dirname, 'default_index.ejs'),
templateParameters: templateParametersGenerator,
filename: 'index.html',
hash: false,
inject: true,
compile: true,
favicon: false,
minify: false,
cache: true,
showErrors: true,
chunks: 'all',
excludeChunks: [],
chunksSortMode: 'auto',
meta: {},
title: 'Webpack App',
xhtml: false
}, options);
簡單介紹一下各個含義
title:{String} 用來生成頁面的 title 元素
template:{String} 源模板文件
inject:{Boolean|String} 放置js資源。true || 'head' || 'body' || false,如果設置為 true 或者 body,所有的 javascript 資源將被放置到 body 元素的底部,'head' 將放置到 head 元素中。false則不會引入。
hash:{Boolean} 將添加一個唯一的 webpack 編譯 hash 到所有包含的腳本和 CSS 文件,對於解除 cache 很有用
favicon:{String} 添加特定的 favicon 路徑到輸出的 HTML 文件中
cache:{Boolean} 只有文件修改后才會重新打包文件
minify:{Boolean|Object} true if mode is 'production', otherwise false,
{
collapseWhitespace: true,//是否去除html中的空格、換行符,元素內的不會去除的
removeComments: true,//是否去除html注釋
removeRedundantAttributes: true,//
removeScriptTypeAttributes: true,//
removeStyleLinkTypeAttributes: true,//
useShortDoctype: true//
}