-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
51 lines (50 loc) · 1.27 KB
/
webpack.config.js
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
const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
mode: 'none',
entry: {
index: './src/index.js',
album: './src/album.js'
},
output: {
filename: '[name].bundle.js',
path: path.join(__dirname, 'dist')
},
optimization: {
splitChunks: {
// 对所有的 chunk 提取公共 chunk
chunks: 'all',
// webpack 5 不再支持自动命名,需要手动配置
name: 'common-chunk'
}
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
plugins: [
// CleanWebpackPlugin 默认根据配置的 output.path 路径进行清空,不配置 output.path 不生效
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Multi Entry',
template: './src/index.html',
filename: 'index.html',
// 允许插入到模板中的一些 chunk,不配置此项默认会将 entry 中所有的 chunk 注入到模板中
chunks: ['index']
}),
new HtmlWebpackPlugin({
title: 'Multi Entry',
template: './src/album.html',
filename: 'album.html',
chunks: ['album']
})
]
}