|
| 1 | + |
| 2 | + |
| 3 | +# example.js |
| 4 | + |
| 5 | +``` javascript |
| 6 | +require(["./a", "./b", "./c"], function(a, b, c) {}); |
| 7 | + |
| 8 | +require.ensure(["./a"], function(require) { |
| 9 | + require("./b"); |
| 10 | + require("./d"); |
| 11 | +}); |
| 12 | + |
| 13 | +require.ensure(["./a", "./e"], function(require) { |
| 14 | + require("./a"); |
| 15 | + require.ensure(["./b"], function(require) { |
| 16 | + require("./f"); |
| 17 | + }); |
| 18 | + require.ensure(["./b"], function(require) { |
| 19 | + require("./g"); |
| 20 | + }); |
| 21 | +}); |
| 22 | +``` |
| 23 | + |
| 24 | +# webpack.config.js |
| 25 | + |
| 26 | +``` javascript |
| 27 | +var path = require("path"); |
| 28 | +var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin"); |
| 29 | +module.exports = { |
| 30 | + plugins: [ |
| 31 | + new CommonsChunkPlugin({ |
| 32 | + name: "main", |
| 33 | + async: "async1" |
| 34 | + }), |
| 35 | + new CommonsChunkPlugin({ |
| 36 | + name: "main", |
| 37 | + async: "async2", |
| 38 | + minChunks: 2 |
| 39 | + }), |
| 40 | + new CommonsChunkPlugin({ |
| 41 | + async: true |
| 42 | + }), |
| 43 | + ] |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +# js/output.js |
| 48 | + |
| 49 | +``` javascript |
| 50 | +/******/ (function(modules) { // webpackBootstrap |
| 51 | +/******/ // install a JSONP callback for chunk loading |
| 52 | +/******/ var parentJsonpFunction = window["webpackJsonp"]; |
| 53 | +/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) { |
| 54 | +/******/ // add "moreModules" to the modules object, |
| 55 | +/******/ // then flag all "chunkIds" as loaded and fire callback |
| 56 | +/******/ var moduleId, chunkId, i = 0, callbacks = []; |
| 57 | +/******/ for(;i < chunkIds.length; i++) { |
| 58 | +/******/ chunkId = chunkIds[i]; |
| 59 | +/******/ if(installedChunks[chunkId]) |
| 60 | +/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]); |
| 61 | +/******/ installedChunks[chunkId] = 0; |
| 62 | +/******/ } |
| 63 | +/******/ for(moduleId in moreModules) { |
| 64 | +/******/ modules[moduleId] = moreModules[moduleId]; |
| 65 | +/******/ } |
| 66 | +/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules); |
| 67 | +/******/ while(callbacks.length) |
| 68 | +/******/ callbacks.shift().call(null, __webpack_require__); |
| 69 | +/******/ |
| 70 | +/******/ }; |
| 71 | +/******/ |
| 72 | +/******/ // The module cache |
| 73 | +/******/ var installedModules = {}; |
| 74 | +/******/ |
| 75 | +/******/ // object to store loaded and loading chunks |
| 76 | +/******/ // "0" means "already loaded" |
| 77 | +/******/ // Array means "loading", array contains callbacks |
| 78 | +/******/ var installedChunks = { |
| 79 | +/******/ 2:0 |
| 80 | +/******/ }; |
| 81 | +/******/ |
| 82 | +/******/ // The require function |
| 83 | +/******/ function __webpack_require__(moduleId) { |
| 84 | +/******/ |
| 85 | +/******/ // Check if module is in cache |
| 86 | +/******/ if(installedModules[moduleId]) |
| 87 | +/******/ return installedModules[moduleId].exports; |
| 88 | +/******/ |
| 89 | +/******/ // Create a new module (and put it into the cache) |
| 90 | +/******/ var module = installedModules[moduleId] = { |
| 91 | +/******/ exports: {}, |
| 92 | +/******/ id: moduleId, |
| 93 | +/******/ loaded: false |
| 94 | +/******/ }; |
| 95 | +/******/ |
| 96 | +/******/ // Execute the module function |
| 97 | +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 98 | +/******/ |
| 99 | +/******/ // Flag the module as loaded |
| 100 | +/******/ module.loaded = true; |
| 101 | +/******/ |
| 102 | +/******/ // Return the exports of the module |
| 103 | +/******/ return module.exports; |
| 104 | +/******/ } |
| 105 | +/******/ |
| 106 | +/******/ // This file contains only the entry chunk. |
| 107 | +/******/ // The chunk loading function for additional chunks |
| 108 | +/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) { |
| 109 | +/******/ // "0" is the signal for "already loaded" |
| 110 | +/******/ if(installedChunks[chunkId] === 0) |
| 111 | +/******/ return callback.call(null, __webpack_require__); |
| 112 | +/******/ |
| 113 | +/******/ // an array means "currently loading". |
| 114 | +/******/ if(installedChunks[chunkId] !== undefined) { |
| 115 | +/******/ installedChunks[chunkId].push(callback); |
| 116 | +/******/ } else { |
| 117 | +/******/ // start chunk loading |
| 118 | +/******/ installedChunks[chunkId] = [callback]; |
| 119 | +/******/ var head = document.getElementsByTagName('head')[0]; |
| 120 | +/******/ var script = document.createElement('script'); |
| 121 | +/******/ script.type = 'text/javascript'; |
| 122 | +/******/ script.charset = 'utf-8'; |
| 123 | +/******/ script.async = true; |
| 124 | +/******/ script.src = __webpack_require__.p + "" + chunkId + ".output.js"; |
| 125 | +/******/ head.appendChild(script); |
| 126 | +/******/ } |
| 127 | +/******/ }; |
| 128 | +/******/ |
| 129 | +/******/ // expose the modules object (__webpack_modules__) |
| 130 | +/******/ __webpack_require__.m = modules; |
| 131 | +/******/ |
| 132 | +/******/ // expose the module cache |
| 133 | +/******/ __webpack_require__.c = installedModules; |
| 134 | +/******/ |
| 135 | +/******/ // __webpack_public_path__ |
| 136 | +/******/ __webpack_require__.p = "js/"; |
| 137 | +/******/ |
| 138 | +/******/ // Load entry module and return exports |
| 139 | +/******/ return __webpack_require__(0); |
| 140 | +/******/ }) |
| 141 | +/************************************************************************/ |
| 142 | +/******/ ([ |
| 143 | +/* 0 */ |
| 144 | +/*!********************!*\ |
| 145 | + !*** ./example.js ***! |
| 146 | + \********************/ |
| 147 | +/***/ function(module, exports, __webpack_require__) { |
| 148 | + |
| 149 | + (function(/* require */) {var __WEBPACK_REMAINING_CHUNKS__ = 3;var __WEBPACK_CALLBACK__ = function() {if(--__WEBPACK_REMAINING_CHUNKS__ < 1) (function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [__webpack_require__(/*! ./a */ 1), __webpack_require__(/*! ./b */ 2), __webpack_require__(/*! ./c */ 3)]; (function(a, b, c) {}.apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));}(__webpack_require__));};__webpack_require__.e(0, __WEBPACK_CALLBACK__);__webpack_require__.e(1, __WEBPACK_CALLBACK__);__webpack_require__.e(5, __WEBPACK_CALLBACK__);}()); |
| 150 | + |
| 151 | + (function(/* nsure */) {var __WEBPACK_REMAINING_CHUNKS__ = 3;var __WEBPACK_CALLBACK__ = function() {if(--__WEBPACK_REMAINING_CHUNKS__ < 1) (function(require) { |
| 152 | + __webpack_require__(/*! ./b */ 2); |
| 153 | + __webpack_require__(/*! ./d */ 4); |
| 154 | + }(__webpack_require__));};__webpack_require__.e(0, __WEBPACK_CALLBACK__);__webpack_require__.e(1, __WEBPACK_CALLBACK__);__webpack_require__.e(4, __WEBPACK_CALLBACK__);}()); |
| 155 | + |
| 156 | + (function(/* nsure */) {var __WEBPACK_REMAINING_CHUNKS__ = 2;var __WEBPACK_CALLBACK__ = function() {if(--__WEBPACK_REMAINING_CHUNKS__ < 1) (function(require) { |
| 157 | + __webpack_require__(/*! ./a */ 1); |
| 158 | + (function(/* nsure */) {var __WEBPACK_REMAINING_CHUNKS__ = 2;var __WEBPACK_CALLBACK__ = function() {if(--__WEBPACK_REMAINING_CHUNKS__ < 1) (function(require) { |
| 159 | + __webpack_require__(/*! ./f */ 6); |
| 160 | + }(__webpack_require__));};__webpack_require__.e(0, __WEBPACK_CALLBACK__);__webpack_require__.e(7, __WEBPACK_CALLBACK__);}()); |
| 161 | + (function(/* nsure */) {var __WEBPACK_REMAINING_CHUNKS__ = 2;var __WEBPACK_CALLBACK__ = function() {if(--__WEBPACK_REMAINING_CHUNKS__ < 1) (function(require) { |
| 162 | + __webpack_require__(/*! ./g */ 7); |
| 163 | + }(__webpack_require__));};__webpack_require__.e(0, __WEBPACK_CALLBACK__);__webpack_require__.e(6, __WEBPACK_CALLBACK__);}()); |
| 164 | + }(__webpack_require__));};__webpack_require__.e(1, __WEBPACK_CALLBACK__);__webpack_require__.e(3, __WEBPACK_CALLBACK__);}()); |
| 165 | + |
| 166 | + |
| 167 | +/***/ } |
| 168 | +/******/ ]) |
| 169 | +``` |
| 170 | + |
| 171 | +# Info |
| 172 | + |
| 173 | +## Uncompressed |
| 174 | + |
| 175 | +``` |
| 176 | +Hash: d802167b5bd787d676e6 |
| 177 | +Version: webpack 1.4.15 |
| 178 | +Time: 70ms |
| 179 | + Asset Size Chunks Chunk Names |
| 180 | +0.output.js 180 0 [emitted] async2 |
| 181 | +1.output.js 186 1 [emitted] async1 |
| 182 | + output.js 5727 2 [emitted] main |
| 183 | +3.output.js 180 3 [emitted] |
| 184 | +4.output.js 180 4 [emitted] |
| 185 | +5.output.js 180 5 [emitted] |
| 186 | +6.output.js 180 6 [emitted] |
| 187 | +7.output.js 180 7 [emitted] |
| 188 | +chunk {0} 0.output.js (async2) 21 {2} {3} [rendered] |
| 189 | + > async commons [0] ./example.js 1:0-52 |
| 190 | + > async commons [0] ./example.js 3:0-6:2 |
| 191 | + > duplicate async commons [0] ./example.js 10:1-12:3 |
| 192 | + > duplicate async commons [0] ./example.js 13:1-15:3 |
| 193 | + [2] ./b.js 21 {0} [built] |
| 194 | + amd require ./b [0] ./example.js 1:0-52 |
| 195 | + cjs require ./b [0] ./example.js 4:1-15 |
| 196 | + require.ensure item ./b [0] ./example.js 10:1-12:3 |
| 197 | + require.ensure item ./b [0] ./example.js 13:1-15:3 |
| 198 | +chunk {1} 1.output.js (async1) 21 {2} [rendered] |
| 199 | + > async commons [0] ./example.js 1:0-52 |
| 200 | + > async commons [0] ./example.js 3:0-6:2 |
| 201 | + > async commons [0] ./example.js 8:0-16:2 |
| 202 | + [1] ./a.js 21 {1} [built] |
| 203 | + amd require ./a [0] ./example.js 1:0-52 |
| 204 | + require.ensure item ./a [0] ./example.js 3:0-6:2 |
| 205 | + require.ensure item ./a [0] ./example.js 8:0-16:2 |
| 206 | + cjs require ./a [0] ./example.js 9:1-15 |
| 207 | +chunk {2} output.js (main) 362 [rendered] |
| 208 | + > main [0] ./example.js |
| 209 | + [0] ./example.js 362 {2} [built] |
| 210 | +chunk {3} 3.output.js 21 {2} [rendered] |
| 211 | + > [0] ./example.js 8:0-16:2 |
| 212 | + [5] ./e.js 21 {3} [built] |
| 213 | + require.ensure item ./e [0] ./example.js 8:0-16:2 |
| 214 | +chunk {4} 4.output.js 21 {2} [rendered] |
| 215 | + > [0] ./example.js 3:0-6:2 |
| 216 | + [4] ./d.js 21 {4} [built] |
| 217 | + cjs require ./d [0] ./example.js 5:1-15 |
| 218 | +chunk {5} 5.output.js 21 {2} [rendered] |
| 219 | + > [0] ./example.js 1:0-52 |
| 220 | + [3] ./c.js 21 {5} [built] |
| 221 | + amd require ./c [0] ./example.js 1:0-52 |
| 222 | +chunk {6} 6.output.js 21 {3} [rendered] |
| 223 | + > [0] ./example.js 13:1-15:3 |
| 224 | + [7] ./g.js 21 {6} [built] |
| 225 | + cjs require ./g [0] ./example.js 14:2-16 |
| 226 | +chunk {7} 7.output.js 21 {3} [rendered] |
| 227 | + > [0] ./example.js 10:1-12:3 |
| 228 | + [6] ./f.js 21 {7} [built] |
| 229 | + cjs require ./f [0] ./example.js 11:2-16 |
| 230 | +``` |
| 231 | + |
| 232 | +## Minimized (uglify-js, no zip) |
| 233 | + |
| 234 | +``` |
| 235 | +Hash: e7c7815873cbcaadbd7d |
| 236 | +Version: webpack 1.4.15 |
| 237 | +Time: 200ms |
| 238 | + Asset Size Chunks Chunk Names |
| 239 | +0.output.js 49 0 [emitted] async2 |
| 240 | +1.output.js 48 1 [emitted] async1 |
| 241 | + output.js 1192 2 [emitted] main |
| 242 | +3.output.js 49 3 [emitted] |
| 243 | +4.output.js 49 4 [emitted] |
| 244 | +5.output.js 49 5 [emitted] |
| 245 | +6.output.js 49 6 [emitted] |
| 246 | +7.output.js 49 7 [emitted] |
| 247 | +chunk {0} 0.output.js (async2) 21 {2} {3} [rendered] |
| 248 | + > async commons [0] ./example.js 1:0-52 |
| 249 | + > async commons [0] ./example.js 3:0-6:2 |
| 250 | + > duplicate async commons [0] ./example.js 10:1-12:3 |
| 251 | + > duplicate async commons [0] ./example.js 13:1-15:3 |
| 252 | + [2] ./b.js 21 {0} [built] |
| 253 | + amd require ./b [0] ./example.js 1:0-52 |
| 254 | + cjs require ./b [0] ./example.js 4:1-15 |
| 255 | + require.ensure item ./b [0] ./example.js 10:1-12:3 |
| 256 | + require.ensure item ./b [0] ./example.js 13:1-15:3 |
| 257 | +chunk {1} 1.output.js (async1) 21 {2} [rendered] |
| 258 | + > async commons [0] ./example.js 1:0-52 |
| 259 | + > async commons [0] ./example.js 3:0-6:2 |
| 260 | + > async commons [0] ./example.js 8:0-16:2 |
| 261 | + [1] ./a.js 21 {1} [built] |
| 262 | + amd require ./a [0] ./example.js 1:0-52 |
| 263 | + require.ensure item ./a [0] ./example.js 3:0-6:2 |
| 264 | + require.ensure item ./a [0] ./example.js 8:0-16:2 |
| 265 | + cjs require ./a [0] ./example.js 9:1-15 |
| 266 | +chunk {2} output.js (main) 362 [rendered] |
| 267 | + > main [0] ./example.js |
| 268 | + [0] ./example.js 362 {2} [built] |
| 269 | +chunk {3} 3.output.js 21 {2} [rendered] |
| 270 | + > [0] ./example.js 8:0-16:2 |
| 271 | + [5] ./e.js 21 {3} [built] |
| 272 | + require.ensure item ./e [0] ./example.js 8:0-16:2 |
| 273 | +chunk {4} 4.output.js 21 {2} [rendered] |
| 274 | + > [0] ./example.js 3:0-6:2 |
| 275 | + [4] ./d.js 21 {4} [built] |
| 276 | + cjs require ./d [0] ./example.js 5:1-15 |
| 277 | +chunk {5} 5.output.js 21 {2} [rendered] |
| 278 | + > [0] ./example.js 1:0-52 |
| 279 | + [3] ./c.js 21 {5} [built] |
| 280 | + amd require ./c [0] ./example.js 1:0-52 |
| 281 | +chunk {6} 6.output.js 21 {3} [rendered] |
| 282 | + > [0] ./example.js 13:1-15:3 |
| 283 | + [7] ./g.js 21 {6} [built] |
| 284 | + cjs require ./g [0] ./example.js 14:2-16 |
| 285 | +chunk {7} 7.output.js 21 {3} [rendered] |
| 286 | + > [0] ./example.js 10:1-12:3 |
| 287 | + [6] ./f.js 21 {7} [built] |
| 288 | + cjs require ./f [0] ./example.js 11:2-16 |
| 289 | +
|
| 290 | +WARNING in output.js from UglifyJs |
| 291 | +Dropping unused function argument c [./example.js:1,0] |
| 292 | +Dropping unused function argument b [./example.js:1,0] |
| 293 | +Dropping unused function argument a [./example.js:1,0] |
| 294 | +Dropping unused function argument require [./example.js:3,0] |
| 295 | +Dropping unused function argument require [./example.js:10,0] |
| 296 | +Dropping unused function argument require [./example.js:13,0] |
| 297 | +Dropping unused function argument require [./example.js:8,0] |
| 298 | +``` |
0 commit comments