Skip to content

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

Closed

Description

@Pliman

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?

Activity

  1. jantimon commented on Jan 5, 2016

    @jantimon
    Owner
  2. Pliman commented on Jan 6, 2016

    @Pliman
    Author

    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]-->
    
  3. jantimon commented on Jan 7, 2016

    @jantimon
    Owner

    Cool 👍

  4. saalmaan commented on May 12, 2016

    @saalmaan

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

  5. Pliman commented on May 23, 2016

    @Pliman
    Author

    Thanks for notification.

  6. giiska commented on Nov 22, 2016

    @giiska

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

  7. jantimon commented on Nov 22, 2016

    @jantimon
    Owner

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

  8. lastobelus commented on Jan 16, 2018

    @lastobelus

    link is broken, even when changing github user.

  9. lock commented on May 31, 2018

    @lock

    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.

  10. locked as resolved and limited conversation to collaborators on May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions