I got an issue with 2.7.2 version. I am trying to use some templated variables in my template, such as:
<title>[<%= htmlWebpackPlugin.options.environment %>] FooBar Project</title>
Yet, it doesn't seem to work, even with the related code:
new HtmlWebpackPlugin({
filename: '/app/index.html',
template: __dirname + '/../app/src/index.html',
hash: true,
environment: 'dev'
})
Am I missing something? :)
If you use a html file and use a html loader the underscore template won't be executed.
So exclude the template or rename it e.g. index.ejs
@jantimon could he use the same name if chained with the underscore-template-loader?
E.g.
new HtmlWebpackPlugin({
filename: '/app/index.html',
template: 'underscore-template!'+__dirname + '/../app/src/index.html',
hash: true,
environment: 'dev'
})
yes this would also work
Indeed, I was using a HTML loader. I solved my issue my excluding my template file from the loader:
{ test: /\.html$/, loader: 'html', include: [sourceDir, commonDir], exclude: /index\.html$/ },
Thanks for your help! :)
@simshanith thanks for help however could you correct the typo in "undescore-template"?
@szymexpawlowski thus amended
i was using raw loader, and just exclude the file i want fix my issue.
{
test: /\.html$/,
use: 'raw-loader',
exclude: [helpers.root('src/index.html'), helpers.root('src/map.html')]
},
and htmlWebpackPlugin
new HtmlWebpackPlugin({
template: 'src/index.html',
title: METADATA.title,
chunksSortMode: 'dependency',
metadata: METADATA,
inject: 'head',
CHAT: process.env.CHAT
}),
new HtmlWebpackPlugin({
filename: 'map.html',
template: 'src/map.html',
title: METADATA.title,
inject: true,
chunks: [],
BASE_URL_API: process.env.BASE_URL_API
}),
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Indeed, I was using a HTML loader. I solved my issue my excluding my template file from the loader:
Thanks for your help! :)