File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ {}
Original file line number Diff line number Diff line change 1
1
# 分片
2
2
3
+ > 状态:草稿
4
+
3
5
![ chunks] ( ../images/chapter3/chunks/1.1.png )
6
+
7
+ example1中使用了` require.ensure ` 和AMD动态` require ` 两种方式,来建立分割点,代码在此处被分片。
8
+
9
+
10
+ ``` javascript
11
+ var a= require (' ./a' );
12
+ a .sayHello ();
13
+
14
+ require .ensure ([' ./b' ], function (require ){
15
+ var b = require (' ./b' );
16
+ b .sayHello ();
17
+ });
18
+
19
+ require ([' ./c' ], function (c ){
20
+ c .sayHello ();
21
+ });
22
+
23
+ ```
24
+
25
+ 打包后的代码:
26
+
27
+ - bundle.js -> main.js + a.js
28
+ - 1.bundle.js -> b.js
29
+ - 2.bundle.js -> c.js
30
+
31
+ ## 多入口
32
+
33
+ 多入口的情况下:
34
+
35
+ - 入口1 bundle.main1.js -> main.js + a.js
36
+ - 入口2 bundle.main2.js -> main2.js + a.js
37
+ - 1.bundle.1.js -> b.js
38
+ - 2.bundle.2.js -> c.js
39
+
40
+ 可见公共代码a.js并没有被提取出来。
41
+
42
+ > 因此分片只是分片,并没有代码自动优化作用。
You can’t perform that action at this time.
0 commit comments