Webpack, super cool and great, yay
also running it with grunt-webpack, omg so happy
whats more? some nice fellow made an inliner so I can require .html files, I sure am lucky
var html = require("html!./some_template.html");
only troublesome detail is that an html file containing
<h3><%= any_variable %></h3>
comes out as
module.exports = "<h3><%= any_variable %></h3>"
I feel like I must be missing some silly detail, otherwise maybe the thing to do is alter html-loader? It's a fairly trivial detail but I still feel like I'm misunderstanding this tool.
check it out https://github.com/webpack/html-loader/blob/master/index.js
as requested, from webpack.config.js, or in my case Gruntfile.js
module: {
loaders: [
{ test: /\.html$/, loader: "html" }
]
}
SOLUTION: turns out I can't actually read, require("html!./some_template.html");
runs the loader, and then I was also running it in my config, so I wound up with commonjs declaration in my html.
module. rules allows you to specify several loaders within your webpack configuration. This is a concise way to display loaders, and helps to maintain clean code.
The HtmlWebpackPlugin simplifies creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles that include a hash in the filename which changes every compilation.
template: './src/index. html' – this option specifies which file to use as template for the index. html being created. title: 'My Awesome application' – this is a custom property we added to the config object, the value of this property would be used to embed in the placeholder element <%= htmlWebpackPlugin. options.
There are four basic concepts in webpack: entry , output , modules and plug-ins . These configurations are added in webpack.
For others who are struggling like me here's the solution - https://www.reddit.com/r/javascript/comments/39jp8z/webpack_weirdness_no_love_at_stackoverflow/
Basically the html-loader is running twice!!
Remove either of the setting. (in webpack config or while importing)
It is explicitly coded to do that - https://github.com/webpack/html-loader/blob/master/index.js#L71
You could contact the author through github and/or file an issue there?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With