Multiple Sass & JS files | Question #195
-
Want to know how can I get multiple javascript files as output & as well as multiple sass files? for example here is a dummy layout of the directory: So the expected output would be main, home & about CSS files and the same goes for javascript main, home & about js files. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
So I was able to pull this off using multiple entries
but I don't want all HTML's to have all JS & CSS files only specific JS & CSS in the name specific HTML file. |
Beta Was this translation helpful? Give feedback.
-
Were you able to come up with a solution for this scenario? Our team has a similar use case where we want to build component like pages so we're exporting assets (css and js) for individual components. For example a "page" that just contains one component like a button, marquee, or something larger like a carousel. These can then be imported into other systems. |
Beta Was this translation helpful? Give feedback.
-
For anyone else coming across this scenario, you can use 'chunks'. Firstly you need to declare all of your JS files in Then in the
Note: this is a loop, so we can use the template var (which will be your html file name and ext) and just remove the .html. If you have imported your SCSS into your JS that will get generated too. You can also pass separate global JS files in the chunks array as long as they are declared in |
Beta Was this translation helpful? Give feedback.
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 theentryChunkName
the same as your .html file. e.gabout.html
andabout: 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:Note: this is a loop, so we can use the …