html-webpack-plugin pug-loader 未选择选项

html-webpack-plugin with pug-loader not picking up options

考虑:

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)。

我在这里束手无策,我觉得我错过了一些明显的东西。

您必须将配置更改为:

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