2012-03-10 20:11:23 +08:00
|
|
|
# example.js
|
|
|
|
|
|
|
|
``` javascript
|
2012-03-12 04:37:18 +08:00
|
|
|
function getTemplate(templateName, callback) {
|
|
|
|
require.ensure([], function(require) {
|
|
|
|
callback(require("../require.context/templates/"+templateName));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getTemplate("a", function(a) {
|
|
|
|
console.log(a);
|
|
|
|
});
|
|
|
|
getTemplate("b", function(b) {
|
|
|
|
console.log(b);
|
2012-03-10 20:11:23 +08:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
# js/output.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
/******/(function(document, undefined) {
|
|
|
|
/******/ return function(modules) {
|
|
|
|
/******/ var installedModules = {}, installedChunks = {0:1};
|
|
|
|
/******/ function require(moduleId) {
|
2012-03-20 03:47:58 +08:00
|
|
|
/******/ if(typeof moduleId !== "number") throw new Error("Cannot find module '"+moduleId+"'");
|
2012-03-10 20:11:23 +08:00
|
|
|
/******/ if(installedModules[moduleId])
|
|
|
|
/******/ return installedModules[moduleId].exports;
|
|
|
|
/******/ var module = installedModules[moduleId] = {
|
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/ modules[moduleId](module, module.exports, require);
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
2012-05-22 04:59:31 +08:00
|
|
|
/******/ require.e = function(chunkId, callback) {
|
2012-03-10 20:11:23 +08:00
|
|
|
/******/ 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';
|
2012-04-05 20:59:01 +08:00
|
|
|
/******/ script.charset = 'utf-8';
|
2012-03-10 20:11:23 +08:00
|
|
|
/******/ script.src = modules.c+chunkId+modules.a;
|
|
|
|
/******/ head.appendChild(script);
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
2012-05-17 18:47:06 +08:00
|
|
|
/******/ require.modules = modules;
|
2012-07-11 23:53:46 +08:00
|
|
|
/******/ require.cache = installedModules;
|
2012-03-10 20:11:23 +08:00
|
|
|
/******/ 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) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** .\example.js ***/
|
|
|
|
|
2012-04-05 20:59:01 +08:00
|
|
|
/******/ /* WEBPACK FREE VAR INJECTION */ (function(console) {
|
2012-03-12 04:37:18 +08:00
|
|
|
function getTemplate(templateName, callback) {
|
2012-05-22 04:59:31 +08:00
|
|
|
require.e(1, function(require) {
|
2012-04-08 03:36:55 +08:00
|
|
|
callback(require(/* ../require.context/templates */2)("./"+templateName));
|
2012-03-12 04:37:18 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
getTemplate("a", function(a) {
|
2012-04-05 20:59:01 +08:00
|
|
|
console.log(a);
|
2012-03-12 04:37:18 +08:00
|
|
|
});
|
|
|
|
getTemplate("b", function(b) {
|
2012-04-05 20:59:01 +08:00
|
|
|
console.log(b);
|
2012-03-10 20:11:23 +08:00
|
|
|
});
|
2012-04-08 03:36:55 +08:00
|
|
|
/******/ /* WEBPACK FREE VAR INJECTION */ }(require(/* __webpack_console */1)))
|
2012-03-10 20:11:23 +08:00
|
|
|
|
2012-03-20 03:47:58 +08:00
|
|
|
/******/},
|
|
|
|
/******/
|
2012-04-08 03:36:55 +08:00
|
|
|
/******/1: function(module, exports, require) {
|
2012-03-20 03:47:58 +08:00
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\buildin\__webpack_console.js ***/
|
|
|
|
|
2012-03-20 03:47:58 +08:00
|
|
|
var console = window.console;
|
2012-04-05 20:59:01 +08:00
|
|
|
module.exports = console;
|
|
|
|
for(var name in {log:1, info:1, error:1, warn:1, dir:1, trace:1, assert:1})
|
|
|
|
if(!console[name])
|
|
|
|
console[name] = function() {};
|
|
|
|
if(!console.time)
|
|
|
|
console.time = function(label) {
|
2012-03-20 03:47:58 +08:00
|
|
|
times[label] = Date.now();
|
|
|
|
};
|
2012-04-05 20:59:01 +08:00
|
|
|
if(!console.timeEnd)
|
|
|
|
console.timeEnd = function() {
|
2012-03-20 03:47:58 +08:00
|
|
|
var duration = Date.now() - times[label];
|
2012-04-05 20:59:01 +08:00
|
|
|
console.log('%s: %dms', label, duration);
|
2012-03-20 03:47:58 +08:00
|
|
|
};
|
2012-03-10 20:11:23 +08:00
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/})
|
|
|
|
```
|
|
|
|
|
2012-05-01 16:51:02 +08:00
|
|
|
# js/1.output.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
/******/webpackJsonp(1, {
|
|
|
|
/******/2: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\examples\require.context\templates ***/
|
|
|
|
|
2012-05-17 18:47:06 +08:00
|
|
|
/***/ var map = {"./a.js":3,"./b.js":4,"./c.js":5},
|
|
|
|
/***/requireInContext = module.exports = function(name) {
|
2012-05-01 16:51:02 +08:00
|
|
|
/***/ return require(map[name+""]||map[name+".webpack.js"]||map[name+".web.js"]||map[name+".js"]||name);
|
2012-05-17 18:47:06 +08:00
|
|
|
/***/};/***/requireInContext.keys = function() { return Object.keys(map) }
|
2012-05-01 16:51:02 +08:00
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/3: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\examples\require.context\templates\a.js ***/
|
|
|
|
|
2012-05-01 16:51:02 +08:00
|
|
|
module.exports = function() {
|
|
|
|
return "This text was generated by template A";
|
|
|
|
}
|
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/4: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\examples\require.context\templates\b.js ***/
|
|
|
|
|
2012-05-01 16:51:02 +08:00
|
|
|
module.exports = function() {
|
|
|
|
return "This text was generated by template B";
|
|
|
|
}
|
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/5: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\examples\require.context\templates\c.js ***/
|
|
|
|
|
2012-05-01 16:51:02 +08:00
|
|
|
module.exports = function() {
|
|
|
|
return "This text was generated by template C";
|
|
|
|
}
|
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/})
|
|
|
|
```
|
|
|
|
|
2012-03-10 20:11:23 +08:00
|
|
|
# Info
|
|
|
|
|
|
|
|
## Uncompressed
|
|
|
|
|
2012-03-20 03:47:58 +08:00
|
|
|
```
|
2012-07-11 23:53:46 +08:00
|
|
|
Hash: 07170be22db98a268f11cb614e58f31d
|
|
|
|
Compile Time: 391ms
|
2012-03-20 03:47:58 +08:00
|
|
|
Chunks: 2
|
|
|
|
Modules: 6
|
|
|
|
Modules including duplicates: 6
|
2012-07-11 23:53:46 +08:00
|
|
|
Modules per chunk: 3
|
2012-03-20 03:47:58 +08:00
|
|
|
Modules first chunk: 2
|
2012-07-11 23:53:46 +08:00
|
|
|
output.js: 2804 characters
|
|
|
|
1.output.js: 1088 characters
|
2012-04-08 03:36:55 +08:00
|
|
|
|
|
|
|
<id> <size> <filename>
|
|
|
|
<reason> from <filename>
|
2012-03-20 03:47:58 +08:00
|
|
|
output.js
|
2012-05-22 04:59:31 +08:00
|
|
|
0 268 .\example.js
|
2012-03-20 03:47:58 +08:00
|
|
|
main
|
2012-05-07 03:07:24 +08:00
|
|
|
1 420 (webpack)\buildin\__webpack_console.js
|
2012-04-05 20:59:01 +08:00
|
|
|
require (2x) from .\example.js
|
2012-03-20 03:47:58 +08:00
|
|
|
1.output.js
|
2012-05-17 18:47:06 +08:00
|
|
|
2 289 [context] (webpack)\examples\require.context\templates
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-05-22 04:59:31 +08:00
|
|
|
3 80 (webpack)\examples\require.context\templates\a.js
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-05-22 04:59:31 +08:00
|
|
|
4 80 (webpack)\examples\require.context\templates\b.js
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-05-22 04:59:31 +08:00
|
|
|
5 80 (webpack)\examples\require.context\templates\c.js
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-03-10 20:11:23 +08:00
|
|
|
```
|
|
|
|
|
2012-03-12 04:37:18 +08:00
|
|
|
## Minimized (uglify-js, no zip)
|
2012-03-10 20:11:23 +08:00
|
|
|
|
2012-03-20 03:47:58 +08:00
|
|
|
```
|
2012-07-11 23:53:46 +08:00
|
|
|
Hash: 90d59a1ab3aac4303a445aadd5207854
|
|
|
|
Compile Time: 366ms
|
2012-03-20 03:47:58 +08:00
|
|
|
Chunks: 2
|
|
|
|
Modules: 6
|
|
|
|
Modules including duplicates: 6
|
2012-07-11 23:53:46 +08:00
|
|
|
Modules per chunk: 3
|
2012-03-20 03:47:58 +08:00
|
|
|
Modules first chunk: 2
|
2012-07-11 23:53:46 +08:00
|
|
|
output.js: 1074 characters
|
2012-05-17 18:47:06 +08:00
|
|
|
1.output.js: 473 characters
|
2012-04-08 03:36:55 +08:00
|
|
|
|
|
|
|
<id> <size> <filename>
|
|
|
|
<reason> from <filename>
|
2012-03-20 03:47:58 +08:00
|
|
|
output.js
|
2012-05-22 04:59:31 +08:00
|
|
|
0 157 .\example.js
|
2012-03-20 03:47:58 +08:00
|
|
|
main
|
2012-04-08 03:36:55 +08:00
|
|
|
1 332 (webpack)\buildin\__webpack_console.js
|
2012-04-05 20:59:01 +08:00
|
|
|
require (2x) from .\example.js
|
2012-03-20 03:47:58 +08:00
|
|
|
1.output.js
|
2012-05-17 18:47:06 +08:00
|
|
|
2 228 [context] (webpack)\examples\require.context\templates
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-04-09 20:44:47 +08:00
|
|
|
3 72 (webpack)\examples\require.context\templates\a.js
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-04-09 20:44:47 +08:00
|
|
|
4 72 (webpack)\examples\require.context\templates\b.js
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-04-09 20:44:47 +08:00
|
|
|
5 72 (webpack)\examples\require.context\templates\c.js
|
2012-04-05 20:59:01 +08:00
|
|
|
sync context from .\example.js
|
2012-03-10 20:11:23 +08:00
|
|
|
```
|