Configuring an *.html module loader beats down template variables
Registering a default loader for *.html modules in WebPack breaks the variables resolution in template. For example:
{ test: /\.html$/, loader: "raw-loader" }
In result, the variables are left unresolved:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<script type="text/javascript" src="jquery<%= htmlWebpackPlugin.options.suffix %>.js"></script>
<script type="text/javascript" src="bundle.js"></script></body>
</html>
Changing the test expression to something more detailed fixes the problem:
{ test: /\.jw.html$/, loader: "raw-loader" } // OK!
I've created a minimal repository demonstrating the problem https://github.com/enepomnyaschih/html-plugin-bug
Just run:
git clone [email protected]:enepomnyaschih/html-plugin-bug.git bug
cd bug
npm install
webpack
And check public/index.html file.
Is that expected behaviour?
Yes that's expected behaviour - you can find out more about that in the FAQ :)
Thank you. Could you please give me a little bit more help? Can I somehow specify the fallback loader in "template" config option explicitly? Something like
new HtmlWebpackPlugin({
template: "!!underscore!../templates/base.html"
})
Of course, installing https://www.npmjs.com/package/underscore-loader dependency does the trick, but is it possible to use your built-in loader instead? Also, for some reason, this solution refused to work properly until I changed the template path to "./templates/base.html". See diff
https://github.com/enepomnyaschih/html-plugin-bug/commit/40daa718c338f2c0c87f27d32226bb5c30b1f75d
From https://github.com/ampedandwired/html-webpack-plugin/blob/d22c23066a2905f41b6acb999cbd5d2a5841de30/index.js#L605
"!!html-webpack-plugin/lib/loader.js!../templates/base.html"
This is very helpful, thank you
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.