Below are the webpack config entries :
entry:{
background: './app/main/background.js',
options: './app/main/options.js'
}
One HTML page which is suplied to htmlwebpackplugin as below
new HtmlWebpackPlugin({
template :'./app/templates/options.html',
// chunks : ['jquery','angular','app'],
filename: "./options.html",
cache : true
}),
This results in injecting both background.js
, options.js
in the options.html
page as below:
<script type="text/javascript" src="js/background.js"></script><script type="text/javascript" src="js/options.js"></script></body>
Is there a way to restrict it to only one JS file or specify the file names to be injected in html page?
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.
GitHub - johnagan/clean-webpack-plugin: A webpack plugin to remove your build folder(s) before building. Skip to content Toggle navigation. Product. Actions. Automate any workflow.
The html-loader will parse the URLs, require the images and everything you expect. The extract loader will parse the javascript back into a proper html file, ensuring images are required and point to proper path, and the asset modules will write the .html file for you. Example: webpack.config.js module.
The chunks
option is probably what you want to use (see the filtering chunks section of the documentation). I don't know why it's commented in your snippet but you could write this:
entry: {
background: './app/main/background.js',
options: './app/main/options.js'
}
If you want to only inject the options
entrypoint in the generated HTML, specify the chunks:
new HtmlWebpackPlugin({
template :'./app/templates/options.html',
chunks : ['options'],
filename: "./options.html",
cache : true
}),
Seems you can use html-webpack-exclude-assets-plugin
plugins: [
new HtmlWebpackPlugin({
excludeAssets: [/style.*.js/] // exclude style.js or style.[chunkhash].js
}),
new HtmlWebpackExcludeAssetsPlugin()
]
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