Navigation Menu

Skip to content
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
Closed

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

Pliman opened this issue Jan 5, 2016 · 9 comments

Comments

@Pliman
Copy link

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
Copy link
Owner

jantimon commented Jan 5, 2016

@Pliman
Copy link
Author

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 as completed Jan 6, 2016
@jantimon
Copy link
Owner

jantimon commented Jan 7, 2016

Cool 👍

@saalmaan
Copy link

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
Copy link
Author

Pliman commented May 23, 2016

Thanks for notification.

@giiska
Copy link

giiska commented Nov 22, 2016

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

@jantimon
Copy link
Owner

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

@lastobelus
Copy link

link is broken, even when changing github user.

@lock
Copy link

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.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants