diff --git a/examples/README.md b/examples/README.md index f2a6dfee4..3cee71650 100644 --- a/examples/README.md +++ b/examples/README.md @@ -28,6 +28,10 @@ example demonstrating code written in coffee-script. example demonstrating Code Splitting through the builder loader +## names-chucks + +example demonstrating merging of chucks with named chucks + # Requests If you think a example is missing, please report it as issue. :) diff --git a/examples/buildAll.js b/examples/buildAll.js index aa7efe679..a141e9fd1 100644 --- a/examples/buildAll.js +++ b/examples/buildAll.js @@ -10,4 +10,5 @@ cp.exec("cd coffee-script && node build.js", result); cp.exec("cd loader && node build.js", result); cp.exec("cd require.context && node build.js", result); cp.exec("cd code-splitting-bundle-loader && node build.js", result); -cp.exec("cd commonjs && node build.js", result); \ No newline at end of file +cp.exec("cd commonjs && node build.js", result); +cp.exec("cd named-chucks && node build.js", result); \ No newline at end of file diff --git a/examples/named-chucks/README.md b/examples/named-chucks/README.md new file mode 100644 index 000000000..5a267c64f --- /dev/null +++ b/examples/named-chucks/README.md @@ -0,0 +1,182 @@ +# example.js + +``` javascript +var a = require("a"); + +require.ensure(["b"], function(require) { + // a named chuck + var c = require("c"); +}, "my own chuck"); + +require.ensure(["b"], function(require) { + // another chuck with the same name + var d = require("d"); +}, "my own chuck"); + +require.ensure([], function(require) { + // the same again +}, "my own chuck"); + +require.ensure(["b"], function(require) { + // chuck without name + var d = require("d"); +}); +``` + + +# js/output.js + +``` javascript +/******/(function(document, undefined) { +/******/ return function(modules) { +/******/ var installedModules = {}, installedChunks = {0:1}; +/******/ function require(moduleId) { +/******/ if(typeof moduleId !== "number") throw new Error("Cannot find module '"+moduleId+"'"); +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ var module = installedModules[moduleId] = { +/******/ exports: {} +/******/ }; +/******/ modules[moduleId](module, module.exports, require); +/******/ return module.exports; +/******/ } +/******/ require.ensure = function(chunkId, callback) { +/******/ if(installedChunks[chunkId] === 1) return callback(require); +/******/ if(installedChunks[chunkId] !== undefined) +/******/ installedChunks[chunkId].push(callback); +/******/ else { +/******/ installedChunks[chunkId] = [callback]; +/******/ var head = document.getElementsByTagName('head')[0]; +/******/ var script = document.createElement('script'); +/******/ script.type = 'text/javascript'; +/******/ script.charset = 'utf-8'; +/******/ script.src = modules.c+chunkId+modules.a; +/******/ head.appendChild(script); +/******/ } +/******/ }; +/******/ require.modules = modules; +/******/ window[modules.b] = function(chunkId, moreModules) { +/******/ for(var moduleId in moreModules) +/******/ modules[moduleId] = moreModules[moduleId]; +/******/ var callbacks = installedChunks[chunkId]; +/******/ installedChunks[chunkId] = 1; +/******/ for(var i = 0; i < callbacks.length; i++) +/******/ callbacks[i](require); +/******/ }; +/******/ return require(0); +/******/ } +/******/})(document) +/******/({a:".output.js",b:"webpackJsonp",c:"", +/******/0: function(module, exports, require) { + +var a = require(/* a */3); + +require.ensure(2, function(require) { + // a named chuck + var c = require(/* c */4); +}, /* my own chuck */0); + +require.ensure(2, function(require) { + // another chuck with the same name + var d = require(/* d */2); +}, /* my own chuck */0); + +require.ensure(2, function(require) { + // the same again +}, /* my own chuck */0); + +require.ensure(1, function(require) { + // chuck without name + var d = require(/* d */2); +}); + +/******/}, +/******/ +/******/3: function(module, exports, require) { + +// module a + +/******/}, +/******/ +/******/}) +``` + +# js/1.output.js + +``` javascript +/******/webpackJsonp(1, { +/******/1: function(module, exports, require) { + +// module b + +/******/}, +/******/ +/******/2: function(module, exports, require) { + +// module d + +/******/}, +/******/ +/******/}) +``` + +# js/2.output.js + +``` javascript +/******/webpackJsonp(2, { +/******/1: function(module, exports, require) { + +// module b + +/******/}, +/******/ +/******/2: function(module, exports, require) { + +// module d + +/******/}, +/******/ +/******/4: function(module, exports, require) { + +// module c + +/******/}, +/******/ +/******/}) +``` + +# Info + +## Uncompressed + +``` +Hash: c34ada3b77659fd95fec2420fcfbe923 +Chunks: 3 +Modules: 5 +Modules including duplicates: 7 +Modules pre chunk: 2.3 +Modules first chunk: 2 + output.js: 2371 characters + 1.output.js: 200 characters + 2.output.js: 282 characters + + + from +output.js + 0 461 .\example.js + main + 3 11 .\~\a.js + require (1x) from .\example.js +1.output.js + 1 11 .\~\b.js + async require (3x) from .\example.js + 2 11 .\~\d.js + async require (2x) from .\example.js +2.output.js + 1 11 .\~\b.js + async require (3x) from .\example.js + 2 11 .\~\d.js + async require (2x) from .\example.js + 4 11 .\~\c.js + async require (1x) from .\example.js +``` diff --git a/examples/named-chucks/build.js b/examples/named-chucks/build.js new file mode 100644 index 000000000..41c29c9d1 --- /dev/null +++ b/examples/named-chucks/build.js @@ -0,0 +1 @@ +require("../build-common"); \ No newline at end of file diff --git a/examples/named-chucks/example.js b/examples/named-chucks/example.js new file mode 100644 index 000000000..5e6c30316 --- /dev/null +++ b/examples/named-chucks/example.js @@ -0,0 +1,20 @@ +var a = require("a"); + +require.ensure(["b"], function(require) { + // a named chuck + var c = require("c"); +}, "my own chuck"); + +require.ensure(["b"], function(require) { + // another chuck with the same name + var d = require("d"); +}, "my own chuck"); + +require.ensure([], function(require) { + // the same again +}, "my own chuck"); + +require.ensure(["b"], function(require) { + // chuck without name + var d = require("d"); +}); \ No newline at end of file diff --git a/examples/named-chucks/node_modules/a.js b/examples/named-chucks/node_modules/a.js new file mode 100644 index 000000000..cd84d88ca --- /dev/null +++ b/examples/named-chucks/node_modules/a.js @@ -0,0 +1 @@ +// module a \ No newline at end of file diff --git a/examples/named-chucks/node_modules/b.js b/examples/named-chucks/node_modules/b.js new file mode 100644 index 000000000..1f208ec81 --- /dev/null +++ b/examples/named-chucks/node_modules/b.js @@ -0,0 +1 @@ +// module b \ No newline at end of file diff --git a/examples/named-chucks/node_modules/c.js b/examples/named-chucks/node_modules/c.js new file mode 100644 index 000000000..8c3c879cf --- /dev/null +++ b/examples/named-chucks/node_modules/c.js @@ -0,0 +1 @@ +// module c \ No newline at end of file diff --git a/examples/named-chucks/node_modules/d.js b/examples/named-chucks/node_modules/d.js new file mode 100644 index 000000000..a2fa979d8 --- /dev/null +++ b/examples/named-chucks/node_modules/d.js @@ -0,0 +1 @@ +// module d \ No newline at end of file diff --git a/examples/named-chucks/template.md b/examples/named-chucks/template.md new file mode 100644 index 000000000..1d67edeb3 --- /dev/null +++ b/examples/named-chucks/template.md @@ -0,0 +1,32 @@ +# example.js + +``` javascript +{{example.js}} +``` + + +# js/output.js + +``` javascript +{{js/output.js}} +``` + +# js/1.output.js + +``` javascript +{{js/1.output.js}} +``` + +# js/2.output.js + +``` javascript +{{js/2.output.js}} +``` + +# Info + +## Uncompressed + +``` +{{stdout}} +```