Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring an *.html module loader beats down template variables #540

Closed
enepomnyaschih opened this issue Jan 5, 2017 · 5 comments
Closed

Comments

@enepomnyaschih
Copy link

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 git@github.com:enepomnyaschih/html-plugin-bug.git bug
cd bug
npm install
webpack

And check public/index.html file.

Is that expected behaviour?

@jantimon
Copy link
Owner

jantimon commented Jan 5, 2017

Yes that's expected behaviour - you can find out more about that in the FAQ :)

@jantimon jantimon closed this as completed Jan 5, 2017
@enepomnyaschih
Copy link
Author

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

enepomnyaschih/html-plugin-bug@40daa71

@jantimon
Copy link
Owner

jantimon commented Jan 5, 2017

From https://github.com/ampedandwired/html-webpack-plugin/blob/d22c23066a2905f41b6acb999cbd5d2a5841de30/index.js#L605

"!!html-webpack-plugin/lib/loader.js!../templates/base.html"

@enepomnyaschih
Copy link
Author

This is very helpful, thank you

@lock
Copy link

lock bot commented May 31, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants