-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
52 lines (48 loc) · 1.16 KB
/
webpack.config.js
File metadata and controls
52 lines (48 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const path = require('path');
const fs = require('fs');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const projectsJsonPath = path.join(__dirname, 'projects.config.json');
const projectsData = fs.readFileSync(projectsJsonPath, 'utf-8');
const projects = JSON.parse(projectsData).projects;
const plugins = projects.map(module => new HtmlWebpackPlugin({
filename: `${module}/index.html`,
template: `./src/${module}/index.html`,
chunks: [module],
}));
const entryPoints = projects.reduce((acc, module) => {
acc[module] = `./src/${module}/app.js`;
return acc;
}, {});
module.exports = {
entry: entryPoints,
output: {
filename: '[name]/app.js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.html$/,
use: ['html-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: `index.html`,
template: `./src/index.html`,
}),
...plugins,
],
devServer: {
static: './dist',
hot: true,
watchFiles: ['src/**/*.html'],
},
mode: 'development',
};