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

Can I use conditional comments to import entry script? #155

Closed
Pliman opened this Issue Jan 5, 2016 · 9 comments

Comments

Projects
None yet
5 participants
@Pliman

Pliman commented Jan 5, 2016

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-2e1dwn....js"></script>
<![endif]-->

Any idea on how to achieve that?

@jantimon

This comment has been minimized.

Owner

jantimon commented Jan 5, 2016

@Pliman

This comment has been minimized.

Pliman commented Jan 6, 2016

Ops, I missed that part.

works great for me, thanks a lot.

my scripts:

<!--[if lte IE 9]>
{% for (var chunk in o.htmlWebpackPlugin.files.chunks) { %}
{% if (/^ieCompatible-\w+\.min\.js$/.test(o.htmlWebpackPlugin.files.chunks[chunk].entry)) { %}
<script type="text/javascript" src="{%=o.htmlWebpackPlugin.files.chunks[chunk].entry %}></script>
{% } %}
{% } %}
<![endif]-->

@Pliman Pliman closed this Jan 6, 2016

@jantimon

This comment has been minimized.

Owner

jantimon commented Jan 7, 2016

Cool 👍

@saalmaan

This comment has been minimized.

saalmaan commented May 12, 2016

syntax has changes now, change regular expression according to your chunks
<!--[if lte IE 9]> <% for (var chunk in htmlWebpackPlugin.files.chunks) { %> <% if ((htmlWebpackPlugin.files.chunks[chunk].entry).match('ie')) {%> <script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script> <% } %> <% } %> <![endif]-->

@Pliman

This comment has been minimized.

Pliman commented May 23, 2016

Thanks for notification.

@bammoo

This comment has been minimized.

bammoo commented Nov 22, 2016

@saalmaan How to filter those ie chunks from regular injection?

@jantimon

This comment has been minimized.

Owner

jantimon commented Nov 22, 2016

@bammoo take a look at the html-webpack-exclude-assets-plugin by @jamesjieye - it allows filtering by regular expressions

@lastobelus

This comment has been minimized.

lastobelus commented Jan 16, 2018

link is broken, even when changing github user.

@lock

This comment has been minimized.

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.