Skip to content

Commit 300ee8d

Browse files
committed
added explicit-vendor-chunk example
1 parent fc9b941 commit 300ee8d

File tree

9 files changed

+268
-0
lines changed

9 files changed

+268
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# webpack.config.js
2+
3+
``` javascript
4+
var path = require("path");
5+
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
6+
module.exports = {
7+
entry: {
8+
vendor: "./vendor",
9+
pageA: "./pageA",
10+
pageB: "./pageB",
11+
pageC: "./pageC"
12+
},
13+
output: {
14+
path: path.join(__dirname, "js"),
15+
filename: "[name].js"
16+
},
17+
plugins: [
18+
new CommonsChunkPlugin({
19+
name: "vendor",
20+
minChunks: Infinity
21+
})
22+
]
23+
}
24+
```
25+
26+
# js/vendor.js
27+
28+
``` javascript
29+
/******/ (function(modules) { // webpackBootstrap
30+
/******/ // install a JSONP callback for chunk loading
31+
/******/ var parentJsonpFunction = window["webpackJsonp"];
32+
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
33+
/******/ // add "moreModules" to the modules object,
34+
/******/ // then flag all "chunkIds" as loaded and fire callback
35+
/******/ var moduleId, chunkId, i = 0, callbacks = [];
36+
/******/ for(;i < chunkIds.length; i++) {
37+
/******/ chunkId = chunkIds[i];
38+
/******/ if(installedChunks[chunkId])
39+
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
40+
/******/ installedChunks[chunkId] = 0;
41+
/******/ }
42+
/******/ for(moduleId in moreModules) {
43+
/******/ modules[moduleId] = moreModules[moduleId];
44+
/******/ }
45+
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
46+
/******/ while(callbacks.length)
47+
/******/ callbacks.shift().call(null, __webpack_require__);
48+
/******/ if(moreModules[0]) {
49+
/******/ installedModules[0] = 0;
50+
/******/ return __webpack_require__(0);
51+
/******/ }
52+
/******/ };
53+
54+
/******/ // The module cache
55+
/******/ var installedModules = {};
56+
57+
/******/ // object to store loaded and loading chunks
58+
/******/ // "0" means "already loaded"
59+
/******/ // Array means "loading", array contains callbacks
60+
/******/ var installedChunks = {
61+
/******/ 0:0
62+
/******/ };
63+
64+
/******/ // The require function
65+
/******/ function __webpack_require__(moduleId) {
66+
67+
/******/ // Check if module is in cache
68+
/******/ if(installedModules[moduleId])
69+
/******/ return installedModules[moduleId].exports;
70+
71+
/******/ // Create a new module (and put it into the cache)
72+
/******/ var module = installedModules[moduleId] = {
73+
/******/ exports: {},
74+
/******/ id: moduleId,
75+
/******/ loaded: false
76+
/******/ };
77+
78+
/******/ // Execute the module function
79+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
80+
81+
/******/ // Flag the module as loaded
82+
/******/ module.loaded = true;
83+
84+
/******/ // Return the exports of the module
85+
/******/ return module.exports;
86+
/******/ }
87+
88+
/******/ // This file contains only the entry chunk.
89+
/******/ // The chunk loading function for additional chunks
90+
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
91+
/******/ // "0" is the signal for "already loaded"
92+
/******/ if(installedChunks[chunkId] === 0)
93+
/******/ return callback.call(null, __webpack_require__);
94+
95+
/******/ // an array means "currently loading".
96+
/******/ if(installedChunks[chunkId] !== undefined) {
97+
/******/ installedChunks[chunkId].push(callback);
98+
/******/ } else {
99+
/******/ // start chunk loading
100+
/******/ installedChunks[chunkId] = [callback];
101+
/******/ var head = document.getElementsByTagName('head')[0];
102+
/******/ var script = document.createElement('script');
103+
/******/ script.type = 'text/javascript';
104+
/******/ script.charset = 'utf-8';
105+
/******/ script.async = true;
106+
107+
/******/ script.src = __webpack_require__.p + "" + chunkId + "." + ({"1":"pageC","2":"pageB","3":"pageA"}[chunkId]||chunkId) + ".js";
108+
/******/ head.appendChild(script);
109+
/******/ }
110+
/******/ };
111+
112+
/******/ // expose the modules object (__webpack_modules__)
113+
/******/ __webpack_require__.m = modules;
114+
115+
/******/ // expose the module cache
116+
/******/ __webpack_require__.c = installedModules;
117+
118+
/******/ // __webpack_public_path__
119+
/******/ __webpack_require__.p = "js/";
120+
121+
/******/ // Load entry module and return exports
122+
/******/ return __webpack_require__(0);
123+
/******/ })
124+
/************************************************************************/
125+
/******/ ([
126+
/* 0 */
127+
/*!*******************!*\
128+
!*** ./vendor.js ***!
129+
\*******************/
130+
/***/ function(module, exports, __webpack_require__) {
131+
132+
module.exports = "Vendor";
133+
134+
/***/ }
135+
/******/ ]);
136+
```
137+
138+
# js/pageA.js
139+
140+
``` javascript
141+
webpackJsonp([3],[
142+
/* 0 */
143+
/*!******************!*\
144+
!*** ./pageA.js ***!
145+
\******************/
146+
/***/ function(module, exports, __webpack_require__) {
147+
148+
module.exports = "pageA";
149+
150+
/***/ }
151+
]);
152+
```
153+
154+
# Info
155+
156+
## Uncompressed
157+
158+
```
159+
Hash: 397b8d39eac5eeca4b98
160+
Version: webpack 1.8.10
161+
Time: 55ms
162+
Asset Size Chunks Chunk Names
163+
vendor.js 3.85 kB 0 [emitted] vendor
164+
pageC.js 193 bytes 1 [emitted] pageC
165+
pageB.js 193 bytes 2 [emitted] pageB
166+
pageA.js 193 bytes 3 [emitted] pageA
167+
chunk {0} vendor.js (vendor) 26 bytes [rendered]
168+
> vendor [0] ./vendor.js
169+
[0] ./vendor.js 26 bytes {0} [built]
170+
chunk {1} pageC.js (pageC) 25 bytes {0} [rendered]
171+
> pageC [0] ./pageC.js
172+
[0] ./pageC.js 25 bytes {1} [built]
173+
chunk {2} pageB.js (pageB) 25 bytes {0} [rendered]
174+
> pageB [0] ./pageB.js
175+
[0] ./pageB.js 25 bytes {2} [built]
176+
chunk {3} pageA.js (pageA) 25 bytes {0} [rendered]
177+
> pageA [0] ./pageA.js
178+
[0] ./pageA.js 25 bytes {3} [built]
179+
```
180+
181+
## Minimized (uglify-js, no zip)
182+
183+
```
184+
Hash: 397b8d39eac5eeca4b98
185+
Version: webpack 1.8.10
186+
Time: 150ms
187+
Asset Size Chunks Chunk Names
188+
vendor.js 804 bytes 0 [emitted] vendor
189+
pageC.js 55 bytes 1 [emitted] pageC
190+
pageB.js 55 bytes 2 [emitted] pageB
191+
pageA.js 55 bytes 3 [emitted] pageA
192+
chunk {0} vendor.js (vendor) 26 bytes [rendered]
193+
> vendor [0] ./vendor.js
194+
[0] ./vendor.js 26 bytes {0} [built]
195+
chunk {1} pageC.js (pageC) 25 bytes {0} [rendered]
196+
> pageC [0] ./pageC.js
197+
[0] ./pageC.js 25 bytes {1} [built]
198+
chunk {2} pageB.js (pageB) 25 bytes {0} [rendered]
199+
> pageB [0] ./pageB.js
200+
[0] ./pageB.js 25 bytes {2} [built]
201+
chunk {3} pageA.js (pageA) 25 bytes {0} [rendered]
202+
> pageA [0] ./pageA.js
203+
[0] ./pageA.js 25 bytes {3} [built]
204+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.NO_TARGET_ARGS = true;
2+
require("../build-common");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head></head>
3+
<body>
4+
<script src="js/vendor.js" charset="utf-8"></script>
5+
<script src="js/pageA.js" charset="utf-8"></script>
6+
</body>
7+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "pageA";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "pageB";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "pageC";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# webpack.config.js
2+
3+
``` javascript
4+
{{webpack.config.js}}
5+
```
6+
7+
# js/vendor.js
8+
9+
``` javascript
10+
{{js/vendor.js}}
11+
```
12+
13+
# js/pageA.js
14+
15+
``` javascript
16+
{{js/pageA.js}}
17+
```
18+
19+
# Info
20+
21+
## Uncompressed
22+
23+
```
24+
{{stdout}}
25+
```
26+
27+
## Minimized (uglify-js, no zip)
28+
29+
```
30+
{{min:stdout}}
31+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "Vendor";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var path = require("path");
2+
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
3+
module.exports = {
4+
entry: {
5+
vendor: "./vendor",
6+
pageA: "./pageA",
7+
pageB: "./pageB",
8+
pageC: "./pageC"
9+
},
10+
output: {
11+
path: path.join(__dirname, "js"),
12+
filename: "[name].js"
13+
},
14+
plugins: [
15+
new CommonsChunkPlugin({
16+
name: "vendor",
17+
minChunks: Infinity
18+
})
19+
]
20+
}

0 commit comments

Comments
 (0)