html-webpack-plugin与pug-loader没有选择

时间:2017-09-26 05:50:12

标签: webpack pug html-webpack-plugin

考虑:

plugins: [
  new HtmlWebpackPlugin({
    template: 'index.pug',
    title: 'Page Title',
    custom: 'Custom'
  })
]

内部index.pug

doctype html
html
  head
    meta(charset="utf-8")
    meta(http-equiv="X-UA-Compatible" content="IE=edge")
    meta(name="viewport" content="width=device-width, initial-scale=1")
    title= htmlWebpackPlugin.options.title

我希望自定义标题能够被选中,但它会输出默认的Webpack App(而custom变量是undefined)。

  • webpack 1.15.0
  • html-web-pack-plugin 2.30.1
  • pug 2.0.0-rc.4

我在我的智慧'到此为止,我感觉到我错过了一些明显的东西。

1 个答案:

答案 0 :(得分:1)

您必须将配置更改为:

plugins: [
  new HtmlWebpackPlugin({
    template: '!!pug-loader!index.pug',
    title: 'Page Title',
    custom: 'Custom'
  })
]

详细了解此https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md#2-setting-a-loader-directly-for-the-template