webpack html-webpack-plugin,我可以使用条件注释来导入入口脚本吗?

sww*_*176 3 webpack

我有多个条目,如:

entry: {
  foo: 'foo.js'
  bar: 'bar.js'
  ie: 'ie.js'
},
output: {
  path: path.join(__dirname, '/dist/'),
  filename: '[name]-[hash].min.js'
}
Run Code Online (Sandbox Code Playgroud)

当我使用 HtmlWebpackPlugin 时,肯定会使用块导入或不导入条目。我希望在 HTML 文件中生成条件注释,例如:

<!--[if lte IE 9]>
  <script type="text/javascript" src="ie-12dx....js"></script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

关于如何实现这一目标的任何想法?

sww*_*176 5

感谢jantimon - html-webpack-plugin 的合作者。

您必须创建一个自定义索引文件:https : //github.com/ampedandwired/html-webpack-plugin/blob/master/default_index.html#L15

根据自定义索引文件示例,我自己制作了:

我的脚本:

<!--[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]-->
Run Code Online (Sandbox Code Playgroud)

效果很好!