Skip to content

Commit 5d327da

Browse files
committed
update
1 parent 1449c42 commit 5d327da

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tutorials/webpack-code-splitting/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Webpack Code Splitting
22

3-
对于大型Web项目来说,把所有代码打包成一个JavaScript文件并不明智,因为这会导致生成的`bundle.js`非常庞大,需要花费更多的时间来加载它,导致用户体验下降。本文将介绍Webpack强大的代码分离(Code Splitting)功能,通过该特性我们可以将一个`bundler.js`文件拆分为多个chunk文件,实现在运行时按需异步加载相关资源。本文将从chunk的角度讲解Webpack的代码分离特性。
3+
对于大型Web项目来说,把所有代码打包成一个JavaScript文件并不明智,因为这会导致生成的`bundle.js`非常庞大,需要花费更多的时间来加载它,导致用户体验下降。本文将介绍Webpack强大的代码分离(Code Splitting)功能,通过该特性我们可以将一个`bundle.js`文件拆分为多个chunk文件,实现在运行时按需异步加载相关资源。本文将从chunk的角度讲解Webpack的代码分离特性。
44

55
项目目录结构如下所示:
66
```
@@ -43,7 +43,9 @@ module.exports = "module d";
4343

4444
如上所示,`a.js``b.js``c.js``d.js`这四个文件都是普通的CommonJS模块。
4545

46-
`page1.js`文件如下所示:
46+
47+
## entry chunk
48+
`page1.js`中引入了`a.js``b.js`模块,如下所示:
4749
```
4850
import a from "./a.js";
4951
import b from "./b.js";
@@ -52,7 +54,7 @@ console.log("module a: ", a);
5254
console.log("module b: ", b);
5355
```
5456

55-
`page2.js`文件如下所示
57+
`page2.js`中引入了`c.js``d.js`模块,如下所示
5658
```
5759
import c from "./c.js";
5860
import d from "./d.js";
@@ -61,6 +63,19 @@ console.log("module c: ", c);
6163
console.log("module d: ", d);
6264
```
6365

66+
`chunk`,英文直译过来是`数据块`的意思,我们可以把一个`chunk`看做是一个文件,这个文件里可以包含一个或多个模块(比如a.js、b.js等)。
67+
68+
`chunk`总的来说可以分为`entry chunk``normal chunk``normal chunk`指的就是`non-entry chunk`
69+
70+
我们首先看一下最简单的`entry chunk`
71+
72+
### string entry
73+
74+
### array entry
75+
76+
### object entry
77+
78+
## normal chunk
6479
`page3.js`文件如下所示:
6580
```
6681
import a from "./a.js";
@@ -75,8 +90,4 @@ require.ensure(["./c.js", "./d.js"], function(){
7590
console.log("module c: ", c);
7691
console.log("module d: ", d);
7792
}, "cd");
78-
```
79-
80-
## entry chunk
81-
82-
## normal chunk
93+
```

0 commit comments

Comments
 (0)