2012-08-23 08:05:07 +08:00
|
|
|
# example.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
function getTemplate(templateName, callback) {
|
|
|
|
require(["../require.context/templates/"+templateName], function(tmpl) {
|
|
|
|
callback(tmpl());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getTemplate("a", function(a) {
|
|
|
|
console.log(a);
|
|
|
|
});
|
|
|
|
getTemplate("b", function(b) {
|
|
|
|
console.log(b);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
# js/output.js
|
|
|
|
|
|
|
|
``` javascript
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ (function(modules) { // webpackBootstrap
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ // The module cache
|
|
|
|
/******/ var installedModules = {};
|
|
|
|
/******/
|
|
|
|
/******/ // object to store loaded and loading chunks
|
|
|
|
/******/ // "0" means "already loaded"
|
|
|
|
/******/ // Array means "loading", array contains callbacks
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/ var installedChunks = {
|
2014-02-12 15:56:54 +08:00
|
|
|
/******/ 1:0
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/ };
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/
|
|
|
|
/******/ // The require function
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ function __webpack_require__(moduleId) {
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ // Check if module is in cache
|
|
|
|
/******/ if(installedModules[moduleId])
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ return installedModules[moduleId].exports;
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = installedModules[moduleId] = {
|
|
|
|
/******/ exports: {},
|
|
|
|
/******/ id: moduleId,
|
|
|
|
/******/ loaded: false
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/
|
|
|
|
/******/ // Flag the module as loaded
|
|
|
|
/******/ module.loaded = true;
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ return module.exports;
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/******/ // This file contains only the entry chunk.
|
|
|
|
/******/ // The chunk loading function for additional chunks
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ // "0" is the signal for "already loaded"
|
|
|
|
/******/ if(installedChunks[chunkId] === 0)
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ return callback.call(null, __webpack_require__);
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/
|
|
|
|
/******/ // an array means "currently loading".
|
|
|
|
/******/ if(installedChunks[chunkId] !== undefined) {
|
|
|
|
/******/ installedChunks[chunkId].push(callback);
|
|
|
|
/******/ } else {
|
|
|
|
/******/ // start chunk loading
|
|
|
|
/******/ installedChunks[chunkId] = [callback];
|
|
|
|
/******/ var head = document.getElementsByTagName('head')[0];
|
|
|
|
/******/ var script = document.createElement('script');
|
|
|
|
/******/ script.type = 'text/javascript';
|
|
|
|
/******/ script.charset = 'utf-8';
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ script.src = __webpack_require__.p + "" + chunkId + ".output.js";
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ head.appendChild(script);
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ __webpack_require__.m = modules;
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/
|
|
|
|
/******/ // expose the module cache
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ __webpack_require__.c = installedModules;
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/ // __webpack_public_path__
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ __webpack_require__.p = "js/";
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ // install a JSONP callback for chunk loading
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ var parentJsonpFunction = window["webpackJsonp"];
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
|
|
|
|
/******/ // add "moreModules" to the modules object,
|
|
|
|
/******/ // then flag all "chunkIds" as loaded and fire callback
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ var moduleId, chunkId, i = 0, callbacks = [];
|
|
|
|
/******/ for(;i < chunkIds.length; i++) {
|
|
|
|
/******/ chunkId = chunkIds[i];
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ if(installedChunks[chunkId])
|
|
|
|
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
|
|
|
|
/******/ installedChunks[chunkId] = 0;
|
|
|
|
/******/ }
|
2013-09-25 04:30:07 +08:00
|
|
|
/******/ for(moduleId in moreModules) {
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ modules[moduleId] = moreModules[moduleId];
|
2013-09-25 04:30:07 +08:00
|
|
|
/******/ }
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ while(callbacks.length)
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ callbacks.shift().call(null, __webpack_require__);
|
2013-12-20 06:25:33 +08:00
|
|
|
/******/
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Load entry module and return exports
|
2014-03-25 17:44:10 +08:00
|
|
|
/******/ return __webpack_require__(0);
|
2013-03-28 17:31:52 +08:00
|
|
|
/******/ })
|
2013-03-27 01:22:30 +08:00
|
|
|
/************************************************************************/
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/ ([
|
|
|
|
/* 0 */
|
2013-01-31 01:49:25 +08:00
|
|
|
/*!********************!*\
|
|
|
|
!*** ./example.js ***!
|
|
|
|
\********************/
|
2014-03-25 17:44:10 +08:00
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2013-01-31 01:49:25 +08:00
|
|
|
|
2013-03-28 17:20:14 +08:00
|
|
|
function getTemplate(templateName, callback) {
|
2014-03-25 17:44:10 +08:00
|
|
|
__webpack_require__.e/* require */(0, function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [__webpack_require__(/*! ../require.context/templates */ 4)("./"+templateName)]; (function(tmpl) {
|
2013-03-28 17:20:14 +08:00
|
|
|
callback(tmpl());
|
|
|
|
}.apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));});
|
|
|
|
}
|
|
|
|
getTemplate("a", function(a) {
|
|
|
|
console.log(a);
|
|
|
|
});
|
|
|
|
getTemplate("b", function(b) {
|
|
|
|
console.log(b);
|
|
|
|
});
|
2012-10-26 21:07:50 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ }
|
2013-12-16 06:30:50 +08:00
|
|
|
/******/ ])
|
2012-08-23 08:05:07 +08:00
|
|
|
```
|
|
|
|
|
2014-02-12 15:56:54 +08:00
|
|
|
# js/0.output.js
|
2012-08-23 08:05:07 +08:00
|
|
|
|
|
|
|
``` javascript
|
2014-02-12 15:56:54 +08:00
|
|
|
webpackJsonp([0],[
|
2013-12-16 06:30:50 +08:00
|
|
|
/* 0 */,
|
|
|
|
/* 1 */
|
2013-02-21 03:50:53 +08:00
|
|
|
/*!*****************************************!*\
|
|
|
|
!*** ../require.context/templates/a.js ***!
|
|
|
|
\*****************************************/
|
2014-03-25 17:44:10 +08:00
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2013-01-31 01:49:25 +08:00
|
|
|
|
2013-03-28 17:20:14 +08:00
|
|
|
module.exports = function() {
|
|
|
|
return "This text was generated by template A";
|
|
|
|
}
|
2012-08-23 08:05:07 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ },
|
2013-12-18 06:22:19 +08:00
|
|
|
/* 2 */
|
2013-02-21 03:50:53 +08:00
|
|
|
/*!*****************************************!*\
|
|
|
|
!*** ../require.context/templates/b.js ***!
|
|
|
|
\*****************************************/
|
2014-03-25 17:44:10 +08:00
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2012-08-23 08:05:07 +08:00
|
|
|
|
2013-03-28 17:20:14 +08:00
|
|
|
module.exports = function() {
|
|
|
|
return "This text was generated by template B";
|
|
|
|
}
|
2012-08-23 08:05:07 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ },
|
2013-12-18 06:22:19 +08:00
|
|
|
/* 3 */
|
2013-02-21 03:50:53 +08:00
|
|
|
/*!*****************************************!*\
|
|
|
|
!*** ../require.context/templates/c.js ***!
|
|
|
|
\*****************************************/
|
2014-03-25 17:44:10 +08:00
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2012-08-23 08:05:07 +08:00
|
|
|
|
2013-03-28 17:20:14 +08:00
|
|
|
module.exports = function() {
|
|
|
|
return "This text was generated by template C";
|
|
|
|
}
|
2012-08-23 08:05:07 +08:00
|
|
|
|
2013-12-18 06:22:19 +08:00
|
|
|
/***/ },
|
|
|
|
/* 4 */
|
|
|
|
/*!*********************************************!*\
|
|
|
|
!*** ../require.context/templates ^\.\/.*$ ***!
|
|
|
|
\*********************************************/
|
2014-03-25 17:44:10 +08:00
|
|
|
/***/ function(module, exports, __webpack_require__) {
|
2013-12-18 06:22:19 +08:00
|
|
|
|
|
|
|
var map = {
|
|
|
|
"./a": 1,
|
|
|
|
"./a.js": 1,
|
|
|
|
"./b": 2,
|
|
|
|
"./b.js": 2,
|
|
|
|
"./c": 3,
|
|
|
|
"./c.js": 3
|
|
|
|
};
|
|
|
|
function webpackContext(req) {
|
2014-03-25 17:44:10 +08:00
|
|
|
return __webpack_require__(webpackContextResolve(req));
|
2013-12-18 06:22:19 +08:00
|
|
|
};
|
|
|
|
function webpackContextResolve(req) {
|
|
|
|
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
|
|
|
|
};
|
|
|
|
webpackContext.keys = function webpackContextKeys() {
|
|
|
|
return Object.keys(map);
|
|
|
|
};
|
|
|
|
webpackContext.resolve = webpackContextResolve;
|
|
|
|
module.exports = webpackContext;
|
|
|
|
|
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ }
|
2013-12-16 06:30:50 +08:00
|
|
|
])
|
2012-08-23 08:05:07 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
# Info
|
|
|
|
|
|
|
|
## Uncompressed
|
|
|
|
|
|
|
|
```
|
2014-02-12 15:56:54 +08:00
|
|
|
Hash: 4d3059fa37467d8d03cd
|
2014-03-25 17:44:10 +08:00
|
|
|
Version: webpack 1.1.0
|
|
|
|
Time: 79ms
|
2013-05-08 21:36:54 +08:00
|
|
|
Asset Size Chunks Chunk Names
|
2014-03-25 17:44:10 +08:00
|
|
|
0.output.js 1653 0 [emitted]
|
|
|
|
output.js 4215 1 [emitted] main
|
2014-02-12 15:56:54 +08:00
|
|
|
chunk {0} 0.output.js 463 {1} [rendered]
|
2014-01-24 20:33:19 +08:00
|
|
|
> [0] ./example.js 2:1-4:3
|
2014-02-12 15:56:54 +08:00
|
|
|
[1] ../require.context/templates/a.js 82 {0} [built]
|
2013-12-18 06:22:19 +08:00
|
|
|
context element ./a.js [4] ../require.context/templates ^\.\/.*$
|
|
|
|
context element ./a [4] ../require.context/templates ^\.\/.*$
|
2014-02-12 15:56:54 +08:00
|
|
|
[2] ../require.context/templates/b.js 82 {0} [built]
|
2013-12-18 06:22:19 +08:00
|
|
|
context element ./b.js [4] ../require.context/templates ^\.\/.*$
|
|
|
|
context element ./b [4] ../require.context/templates ^\.\/.*$
|
2014-02-12 15:56:54 +08:00
|
|
|
[3] ../require.context/templates/c.js 82 {0} [built]
|
2013-12-18 06:22:19 +08:00
|
|
|
context element ./c.js [4] ../require.context/templates ^\.\/.*$
|
|
|
|
context element ./c [4] ../require.context/templates ^\.\/.*$
|
2014-02-12 15:56:54 +08:00
|
|
|
[4] ../require.context/templates ^\.\/.*$ 217 {0} [built]
|
2013-01-31 01:49:25 +08:00
|
|
|
amd require context ../require.context/templates [0] ./example.js 2:1-4:3
|
2014-02-12 15:56:54 +08:00
|
|
|
chunk {1} output.js (main) 261 [rendered]
|
2014-03-25 17:44:10 +08:00
|
|
|
> main [0] ./example.js
|
2014-02-12 15:56:54 +08:00
|
|
|
[0] ./example.js 261 {1} [built]
|
2012-08-23 08:05:07 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Minimized (uglify-js, no zip)
|
|
|
|
|
|
|
|
```
|
2014-03-25 17:44:10 +08:00
|
|
|
Hash: 778ca864b2c010bc8eaf
|
|
|
|
Version: webpack 1.1.0
|
|
|
|
Time: 204ms
|
2013-05-08 21:36:54 +08:00
|
|
|
Asset Size Chunks Chunk Names
|
2014-02-12 15:56:54 +08:00
|
|
|
0.output.js 528 0 [emitted]
|
2014-03-25 17:44:10 +08:00
|
|
|
output.js 867 1 [emitted] main
|
2014-02-12 15:56:54 +08:00
|
|
|
chunk {0} 0.output.js 463 {1} [rendered]
|
2014-01-24 20:33:19 +08:00
|
|
|
> [0] ./example.js 2:1-4:3
|
2014-02-12 15:56:54 +08:00
|
|
|
[1] ../require.context/templates/a.js 82 {0} [built]
|
2013-12-18 06:22:19 +08:00
|
|
|
context element ./a.js [4] ../require.context/templates ^\.\/.*$
|
|
|
|
context element ./a [4] ../require.context/templates ^\.\/.*$
|
2014-02-12 15:56:54 +08:00
|
|
|
[2] ../require.context/templates/b.js 82 {0} [built]
|
2013-12-18 06:22:19 +08:00
|
|
|
context element ./b.js [4] ../require.context/templates ^\.\/.*$
|
|
|
|
context element ./b [4] ../require.context/templates ^\.\/.*$
|
2014-02-12 15:56:54 +08:00
|
|
|
[3] ../require.context/templates/c.js 82 {0} [built]
|
2013-12-18 06:22:19 +08:00
|
|
|
context element ./c.js [4] ../require.context/templates ^\.\/.*$
|
|
|
|
context element ./c [4] ../require.context/templates ^\.\/.*$
|
2014-02-12 15:56:54 +08:00
|
|
|
[4] ../require.context/templates ^\.\/.*$ 217 {0} [built]
|
2013-01-31 01:49:25 +08:00
|
|
|
amd require context ../require.context/templates [0] ./example.js 2:1-4:3
|
2014-02-12 15:56:54 +08:00
|
|
|
chunk {1} output.js (main) 261 [rendered]
|
2014-03-25 17:44:10 +08:00
|
|
|
> main [0] ./example.js
|
2014-02-12 15:56:54 +08:00
|
|
|
[0] ./example.js 261 {1} [built]
|
2012-08-23 08:05:07 +08:00
|
|
|
```
|