【问题标题】:html-webpack-plugin with pug-loader not picking up options带有 pug-loader 的 html-webpack-plugin 没有选择选项
【发布时间】:2017-09-26 05:50:12
【问题描述】:

考虑:

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
  • 哈巴狗 2.0.0-rc.4

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

【问题讨论】:

  • htmlWebpackPlugin 选项仅适用于.ejs 文件。
  • @imcvampire 认真的吗?这在某处有记录吗?
  • 默认只支持ejs。但是你可以配置使用另一个加载器

标签: webpack html-webpack-plugin pug-loader


【解决方案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

【讨论】:

  • 而且,我只是重新加载了开发服务器,而不是观察者,所以我的配置更改根本没有被拾取......呃!
  • 我对这个问题的建议是,当你有一个新的配置时,你应该使用一些文件观察器(nodemon,...)来重新加载。
猜你喜欢
  • 2016-04-25
  • 2023-03-13
  • 2020-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多