Html-webpack-plugin: Template variables are not replaced

Created on 15 Feb 2016  路  8Comments  路  Source: jantimon/html-webpack-plugin

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? :)

Most helpful comment

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! :)

All 8 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GerkinDev picture GerkinDev  路  3Comments

ghaiklor picture ghaiklor  路  3Comments

Rowno picture Rowno  路  3Comments

var-bp picture var-bp  路  3Comments

hackteck picture hackteck  路  3Comments