I have two different modules like students and staff.
- For students files should be created into the dist folder with static path /students' -
publicPath: "/students/". - For staff files should be created into dist folder without static path(root folder).
I set the publicPath: "/students/" but staff files static path also included with students.
I have added the config below
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
entry: {
students: [
'./students/css/students.css',
'./students/js/students.js',
'./students/templates/students/index.pug'
],
staff: [
'./staff/css/index.css',
'./staff/js/index.js',
'./staff/templates/index.pug',
]
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
publicPath: "/students/"
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './students/templates/students/index.pug',
chunks: ['students'],
}),
new HtmlWebpackPlugin({
filename: 'staff.html',
template: './staff/templates/index.pug',
chunks: ['staff'],
})
]
};
You can use Exporting multiple configurations. Create multiple WebPack configurations to build different modules. So that you specify
publicPathfor each config.Folder structure:
E.g.
Output:
dist/staff.html:dist/students.html: