You can pass the custom properties to HtmlWebpackPlugin
options and use them in your pug templates (see htmlWebpackPlugin.options in documentation). It works with the latest versions of the HtmlWebpackPlugin
, pug-loader
and webpack 2. Can't confirm that it works with the previous versions, but I believe it does.
pug
rule:
{
test: /.pug$/,
loader: 'pug-loader',
options: {
// Use `self` namespace to hold the locals
// Not really necessary
self: true,
},
}
HtmlWebpackPlugin
options:
{
filename: 'index.html',
template: 'src/html/index.pug',
// Your custom variables:
name: 'Georg',
}
Using it in index.pug
template:
span= self.htmlWebpackPlugin.options.name
Note that you can set the self
option to false
and omit it in your pug templates using variables directly. For more details see the Pug reference.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…