I have multiple entry like:
entry: {
foo: 'foo.js'
bar: 'bar.js'
ie: 'ie.js'
},
output: {
path: path.join(__dirname, '/dist/'),
filename: '[name]-[hash].min.js'
}
when I use HtmlWebpackPlugin, It's for certain to import or not import an entry, using chunks. I hope to generate conditional comments in HTML file, like:
<!--[if lte IE 9]>
<script type="text/javascript" src="ie-12dx....js"></script>
<![endif]-->
Any idea on how to achieve that?
Thanks to jantimon - collaborator of html-webpack-plugin.
You have to create a custom index file: https://github.com/ampedandwired/html-webpack-plugin/blob/master/default_index.html#L15
According to custom index file example, I made my own:
my scripts:
<!--[if lte IE 9]>
{% for (var chunk in o.htmlWebpackPlugin.files.chunks) { %}
{% if (/^ie-\w+\.min\.js$/.test(o.htmlWebpackPlugin.files.chunks[chunk].entry)) { %}
<script type="text/javascript" src="{%=o.htmlWebpackPlugin.files.chunks[chunk].entry %}></script>
{% } %}
{% } %}
<![endif]-->
works great!
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