I thought a loader is invoked only when some resource is imported or required somewhere and the resources match with such a loader.
But in the following codes, no html file is imported anywhere but the html-loader is still necessary to make the compilation pass because of the underscore template stuff in the html.
So I have the following questions:
- When does the html-loader come to play? After or before the bundle is generated?
- Why does webpack invoke the html-loader? Because of the template setting in the plugin?
Does the plugin use the output of the loader? But the output is just a string and how could it make a difference?
//webpack.config.js const webpack = require('webpack'); const path = require('path'); const htmlPlugin = require('html-webpack-plugin'); module.exports = { entry: { a: './a.js' }, output: { filename: '[name].[chunkhash].js', chunkFilename: '[name].[chunkhash].js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.html$/, loader: "html-loader" } ] }, plugins: [ new htmlPlugin({ template:path.resolve(__dirname,'index.html') }) ] }; //index.html <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script id="item-template" type="text/template"> <label><%= title %></label> </script> </body> </html>
template
field, our template loader, i.e.html-loader
is invoked. – Pursuer<label><%= title %></label>
doesn't work when using html-loader with html webpack plugin, anybody figured out a workaround? – Pickett