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 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?

@Pliman
Copy link
Author

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

@jantimon jantimon commented Jan 7, 2016

Cool 👍

@saalmaan
Copy link

@saalmaan 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 Pliman commented May 23, 2016

Thanks for notification.

@bammoo
Copy link

@bammoo bammoo commented Nov 22, 2016

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

@jantimon
Copy link
Owner

@jantimon 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
Copy link

@lastobelus lastobelus commented Jan 16, 2018

link is broken, even when changing github user.

@lock
Copy link

@lock 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants