Skip to content

Commit 3902a64

Browse files
committed
📝: demo03 README
1 parent 2875778 commit 3902a64

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

demo03/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Demo03 使用 `chunkhash`
2+
3+
**`webpack` 配置文件中将 `[hash]` 替换为 `[chunkhash]`**
4+
5+
```js
6+
// webpack.config.js
7+
module.exports = {
8+
mode: 'production',
9+
entry: {
10+
index: './src/index.js',
11+
},
12+
output: {
13+
path: path.join(__dirname, 'dist'),
14+
filename: '[name]_[chunkhash:8].js',
15+
},
16+
optimization: {
17+
runtimeChunk: true,
18+
splitChunks: {
19+
chunks: 'all'
20+
},
21+
},
22+
};
23+
```
24+
25+
**打包结果 Output**
26+
27+
> 见 dist 文件夹
28+
29+
```zsh
30+
Asset Size Chunks Chunk Names
31+
index_201f4e93.js 168 bytes 0 [emitted] index
32+
runtime~index_2f124e9a.js 1.46 KiB 1 [emitted] runtime~index
33+
vendors~index_07bff0e7.js 69.7 KiB 2 [emitted] vendors~index
34+
```
35+
36+
打包后3个文件都带有不同的 `hash` 值。

0 commit comments

Comments
 (0)