You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-30Lines changed: 33 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,15 @@
5
5
As developer you want to reuse existing code.
6
6
As with node.js and web all file are already in the same language, but it is extra work to use your code with the node.js module system and the browser.
7
7
The goal of `webpack` is to bundle CommonJs modules into javascript files which can be loaded by `<script>`-tags.
8
-
Concating all required file has a disadvantage: many code to download (and execute) on page load.
9
-
Therefor`webpack` uses the `require.ensure` function to split your code automatically into multiple bundles which are loaded on demand.
8
+
Simply concating all required files has a disadvantage: many code to download (and execute) on page load.
9
+
Therefore`webpack` uses the `require.ensure` function ([CommonJs/Modules/Async/A](http://wiki.commonjs.org/wiki/Modules/Async/A)) to split your code automatically into multiple bundles which are loaded on demand.
10
10
This happens mostly transparent to the developer with a single function call. Dependencies are resolved for you.
11
11
The result is a smaller inital code download which results in faster page load.
12
12
13
13
**TL;DR**
14
14
15
-
* bundle CommonJs modules
15
+
* bundle CommonJs modules for browser
16
+
* reuse server-side code (node.js) on client-side
16
17
* create multiple files which are loaded on demand
17
18
* dependencies managed for you
18
19
* faster page load in big webapps
@@ -51,6 +52,31 @@ are compiled to
51
52
})
52
53
```
53
54
55
+
## Code Splitting
56
+
57
+
### Example
58
+
59
+
```javascript
60
+
var a =require("a");
61
+
var b =require("b");
62
+
require.ensure(["c"], function(require) {
63
+
require("b").xyz();
64
+
var d =require("d");
65
+
});
66
+
```
67
+
68
+
```
69
+
File 1: web.js
70
+
- code of module a and dependencies
71
+
- code of module b and dependencies
72
+
73
+
File 2: 1.web.js
74
+
- code of module c and dependencies (but code is not used)
75
+
- code of module d and dependencies
76
+
```
77
+
78
+
See [details](modules-webpack/tree/master/example) for exact output.
79
+
54
80
## Browser replacements
55
81
56
82
Somethings it happens that browsers require other code than node.js do.
@@ -87,31 +113,6 @@ web_modules
87
113
...
88
114
```
89
115
90
-
## Code Splitting
91
-
92
-
### Example
93
-
94
-
```javascript
95
-
var a =require("a");
96
-
var b =require("b");
97
-
require.ensure(["c"], function(require) {
98
-
require("b").xyz();
99
-
var d =require("d");
100
-
});
101
-
```
102
-
103
-
```
104
-
File 1: web.js
105
-
- code of module a and dependencies
106
-
- code of module b and dependencies
107
-
108
-
File 2: 1.web.js
109
-
- code of module c and dependencies (but code is not used)
110
-
- code of module d and dependencies
111
-
```
112
-
113
-
See [details](modules-webpack/tree/master/example) for exact output.
0 commit comments