html-webpack-plugin 详细配置

下面我们介绍一下该插件的配置项。查看源码我们会发现如下代码。

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//
    }

猜你喜欢

转载自www.cnblogs.com/xqzi/p/10712375.html