Answer the question
In order to leave comments, you need to log in
How to embed script in html via webpack?
I'm making 2 files, but only 1 needs to be used, so I can't set inject: true . Is it possible to select the files that are needed?
entry: {
'bundle': './src/js/index.js',
'bundle.min': './src/js/index.js'
},
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: path.resolve(__dirname, '../src/html/index.html'),
files: {
js: [
'bundle.min.js'
]
}
}),
Answer the question
In order to leave comments, you need to log in
HtmlWebpackPlugin has its own templating engine inside. This is how it inserts all the chunks it has.
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question