Skip to content

Multiple Sass & JS files | Question #195

Answered by simonshorten
SuNiL-Chau asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone else coming across this scenario, you can use 'chunks'.

Firstly you need to declare all of your JS files in entry. Make sure to label the entryChunkName the same as your .html file. e.g about.html and about: path.resolve(environment.paths.source, 'js', 'about.js')

Then in the HTMLWebpackPlugin options, pass the name of the JS file in an array like below:

const htmlPluginEntries = templateFiles.map((template) => new HTMLWebpackPlugin({
  inject: true,
  hash: false,
  chunks: [template.replace('.html', '')], // match html file name with JS entry name
  filename: template,
  template: path.resolve(environment.paths.source, template),
}));

Note: this is a loop, so we can use the …

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by pnikolov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants
Converted from issue

This discussion was converted from issue #43 on October 16, 2023 11:40.