updated examples, added bundle loader example
This commit is contained in:
parent
f81c516066
commit
0aad488f90
|
@ -8,4 +8,5 @@ cp.exec("cd code-splitted-require.context && node build.js", result);
|
|||
cp.exec("cd code-splitting && node build.js", result);
|
||||
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 require.context && node build.js", result);
|
||||
cp.exec("cd code-splitting-bundle-loader && node build.js", result);
|
|
@ -153,18 +153,18 @@ Modules first chunk: 2
|
|||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 162 .\example.js
|
||||
0 273 .\example.js
|
||||
main
|
||||
1 332 (webpack)\buildin\__webpack_console.js
|
||||
1 420 (webpack)\buildin\__webpack_console.js
|
||||
require (2x) from .\example.js
|
||||
1.output.js
|
||||
2 143 [context] (webpack)\examples\require.context\templates
|
||||
2 203 [context] (webpack)\examples\require.context\templates
|
||||
sync context from .\example.js
|
||||
3 72 (webpack)\examples\require.context\templates\a.js
|
||||
3 80 (webpack)\examples\require.context\templates\a.js
|
||||
sync context from .\example.js
|
||||
4 72 (webpack)\examples\require.context\templates\b.js
|
||||
4 80 (webpack)\examples\require.context\templates\b.js
|
||||
sync context from .\example.js
|
||||
5 72 (webpack)\examples\require.context\templates\c.js
|
||||
5 80 (webpack)\examples\require.context\templates\c.js
|
||||
sync context from .\example.js
|
||||
```
|
||||
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
# example.js
|
||||
|
||||
``` javascript
|
||||
require("bundle!./file.js")(function(fileJsExports) {
|
||||
console.log(fileJsExports);
|
||||
});
|
||||
```
|
||||
|
||||
# file.js
|
||||
|
||||
``` javascript
|
||||
module.exports = "It works";
|
||||
```
|
||||
|
||||
|
||||
# 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);
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/ 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) {
|
||||
|
||||
/******/ /* WEBPACK FREE VAR INJECTION */ (function(console) {
|
||||
require(/* bundle!./file.js */2)(function(fileJsExports) {
|
||||
console.log(fileJsExports);
|
||||
});
|
||||
/******/ /* WEBPACK FREE VAR INJECTION */ }(require(/* __webpack_console */1)))
|
||||
|
||||
/******/},
|
||||
/******/
|
||||
/******/1: function(module, exports, require) {
|
||||
|
||||
var console = window.console;
|
||||
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) {
|
||||
times[label] = Date.now();
|
||||
};
|
||||
if(!console.timeEnd)
|
||||
console.timeEnd = function() {
|
||||
var duration = Date.now() - times[label];
|
||||
console.log('%s: %dms', label, duration);
|
||||
};
|
||||
|
||||
/******/},
|
||||
/******/
|
||||
/******/2: function(module, exports, require) {
|
||||
|
||||
var cbs = [],
|
||||
data;
|
||||
module.exports = function(cb) {
|
||||
if(cbs) cbs.push(cb);
|
||||
else cb(data);
|
||||
}
|
||||
require.ensure(1, function(require) {
|
||||
data = require(/* !.\file.js */3);
|
||||
var callbacks = cbs;
|
||||
cbs = null;
|
||||
for(var i = 0, l = callbacks.length; i < l; i++) {
|
||||
callbacks[i](data);
|
||||
}
|
||||
});
|
||||
|
||||
/******/},
|
||||
/******/
|
||||
/******/})
|
||||
```
|
||||
|
||||
# js/1.output.js
|
||||
|
||||
``` javascript
|
||||
/******/webpackJsonp(1, {
|
||||
/******/3: function(module, exports, require) {
|
||||
|
||||
module.exports = "It works";
|
||||
|
||||
/******/},
|
||||
/******/
|
||||
/******/})
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
Hash: a5f91336d183b3a3ebd2441528b41903
|
||||
Chunks: 2
|
||||
Modules: 4
|
||||
Modules including duplicates: 4
|
||||
Modules pre chunk: 2
|
||||
Modules first chunk: 3
|
||||
output.js: 2915 characters
|
||||
1.output.js: 135 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 91 .\example.js
|
||||
main
|
||||
1 420 (webpack)\buildin\__webpack_console.js
|
||||
require (1x) from .\example.js
|
||||
2 367 (webpack)\~\bundle-loader!.\file.js
|
||||
require (1x) from .\example.js
|
||||
1.output.js
|
||||
3 28 .\file.js
|
||||
async require (1x) from .\file.js
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
Hash: a5f91336d183b3a3ebd2441528b41903
|
||||
Chunks: 2
|
||||
Modules: 4
|
||||
Modules including duplicates: 4
|
||||
Modules pre chunk: 2
|
||||
Modules first chunk: 3
|
||||
output.js: 1131 characters
|
||||
1.output.js: 57 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 39 .\example.js
|
||||
main
|
||||
1 332 (webpack)\buildin\__webpack_console.js
|
||||
require (1x) from .\example.js
|
||||
2 169 (webpack)\~\bundle-loader!.\file.js
|
||||
require (1x) from .\example.js
|
||||
1.output.js
|
||||
3 25 .\file.js
|
||||
async require (1x) from .\file.js
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
require("../build-common");
|
|
@ -0,0 +1,3 @@
|
|||
require("bundle!./file.js")(function(fileJsExports) {
|
||||
console.log(fileJsExports);
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
module.exports = "It works";
|
|
@ -0,0 +1,38 @@
|
|||
# example.js
|
||||
|
||||
``` javascript
|
||||
{{example.js}}
|
||||
```
|
||||
|
||||
# file.js
|
||||
|
||||
``` javascript
|
||||
{{file.js}}
|
||||
```
|
||||
|
||||
|
||||
# js/output.js
|
||||
|
||||
``` javascript
|
||||
{{js/output.js}}
|
||||
```
|
||||
|
||||
# js/1.output.js
|
||||
|
||||
``` javascript
|
||||
{{js/1.output.js}}
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
{{stdout}}
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
{{min:stdout}}
|
||||
```
|
|
@ -120,16 +120,16 @@ Modules first chunk: 3
|
|||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 82 .\example.js
|
||||
0 155 .\example.js
|
||||
main
|
||||
1 0 .\node_modules\b.js
|
||||
1 11 .\~\b.js
|
||||
require (2x) from .\example.js
|
||||
2 0 .\node_modules\a.js
|
||||
2 11 .\~\a.js
|
||||
require (1x) from .\example.js
|
||||
1.output.js
|
||||
3 0 .\node_modules\c.js
|
||||
3 11 .\~\c.js
|
||||
async require (1x) from .\example.js
|
||||
4 0 .\node_modules\d.js
|
||||
4 11 .\~\d.js
|
||||
async require (1x) from .\example.js
|
||||
```
|
||||
|
||||
|
@ -150,13 +150,13 @@ Modules first chunk: 3
|
|||
output.js
|
||||
0 82 .\example.js
|
||||
main
|
||||
1 0 .\node_modules\b.js
|
||||
1 0 .\~\b.js
|
||||
require (2x) from .\example.js
|
||||
2 0 .\node_modules\a.js
|
||||
2 0 .\~\a.js
|
||||
require (1x) from .\example.js
|
||||
1.output.js
|
||||
3 0 .\node_modules\c.js
|
||||
3 0 .\~\c.js
|
||||
async require (1x) from .\example.js
|
||||
4 0 .\node_modules\d.js
|
||||
4 0 .\~\d.js
|
||||
async require (1x) from .\example.js
|
||||
```
|
||||
|
|
|
@ -116,19 +116,19 @@ Modules: 4
|
|||
Modules including duplicates: 4
|
||||
Modules pre chunk: 4
|
||||
Modules first chunk: 4
|
||||
output.js: 1951 characters
|
||||
output.js: 1951 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 23 .\example.js
|
||||
0 43 .\example.js
|
||||
main
|
||||
1 332 (webpack)\buildin\__webpack_console.js
|
||||
1 420 (webpack)\buildin\__webpack_console.js
|
||||
require (1x) from .\example.js
|
||||
require (1x) from .\cup2.coffee
|
||||
2 76 (webpack)\node_modules\coffee-loader\index.js!.\cup2.coffee
|
||||
2 92 (webpack)\~\coffee-loader!.\cup2.coffee
|
||||
require (2x) from .\cup1.coffee
|
||||
3 101 (webpack)\node_modules\coffee-loader\index.js!.\cup1.coffee
|
||||
3 178 (webpack)\~\coffee-loader!.\cup1.coffee
|
||||
require (1x) from .\example.js
|
||||
```
|
||||
|
||||
|
@ -141,7 +141,7 @@ Modules: 4
|
|||
Modules including duplicates: 4
|
||||
Modules pre chunk: 4
|
||||
Modules first chunk: 4
|
||||
output.js: 784 characters
|
||||
output.js: 784 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
|
@ -151,8 +151,8 @@ output.js
|
|||
1 332 (webpack)\buildin\__webpack_console.js
|
||||
require (1x) from .\example.js
|
||||
require (1x) from .\cup2.coffee
|
||||
2 76 (webpack)\node_modules\coffee-loader\index.js!.\cup2.coffee
|
||||
2 76 (webpack)\~\coffee-loader!.\cup2.coffee
|
||||
require (2x) from .\cup1.coffee
|
||||
3 101 (webpack)\node_modules\coffee-loader\index.js!.\cup1.coffee
|
||||
3 101 (webpack)\~\coffee-loader!.\cup1.coffee
|
||||
require (1x) from .\example.js
|
||||
```
|
|
@ -136,20 +136,20 @@ Modules: 5
|
|||
Modules including duplicates: 5
|
||||
Modules pre chunk: 5
|
||||
Modules first chunk: 5
|
||||
output.js: 2063 characters
|
||||
output.js: 2063 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 109 .\example.js
|
||||
0 333 .\example.js
|
||||
main
|
||||
1 332 (webpack)\buildin\__webpack_console.js
|
||||
1 420 (webpack)\buildin\__webpack_console.js
|
||||
require (3x) from .\example.js
|
||||
2 28 (webpack)\node_modules\json-loader\index.js!.\test.json
|
||||
2 36 (webpack)\~\json-loader!.\test.json
|
||||
require (1x) from .\example.js
|
||||
require (1x) from .\example.js
|
||||
3 35 .\loader.js!.\file.js
|
||||
3 41 .\loader.js!.\file.js
|
||||
require (1x) from .\example.js
|
||||
4 36 (webpack)\require-polyfill.web.js
|
||||
4 87 (webpack)\require-polyfill.web.js
|
||||
require (1x) from .\example.js
|
||||
```
|
|
@ -121,22 +121,22 @@ Modules: 6
|
|||
Modules including duplicates: 6
|
||||
Modules pre chunk: 6
|
||||
Modules first chunk: 6
|
||||
output.js: 2236 characters
|
||||
output.js: 2236 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
output.js
|
||||
0 109 .\example.js
|
||||
0 156 .\example.js
|
||||
main
|
||||
1 332 (webpack)\buildin\__webpack_console.js
|
||||
1 420 (webpack)\buildin\__webpack_console.js
|
||||
require (2x) from .\example.js
|
||||
2 143 [context] .\templates
|
||||
2 203 [context] .\templates
|
||||
context from .\example.js
|
||||
3 72 .\templates\a.js
|
||||
3 80 .\templates\a.js
|
||||
context from .\example.js
|
||||
4 72 .\templates\b.js
|
||||
4 80 .\templates\b.js
|
||||
context from .\example.js
|
||||
5 72 .\templates\c.js
|
||||
5 80 .\templates\c.js
|
||||
context from .\example.js
|
||||
```
|
||||
|
||||
|
@ -149,7 +149,7 @@ Modules: 6
|
|||
Modules including duplicates: 6
|
||||
Modules pre chunk: 6
|
||||
Modules first chunk: 6
|
||||
output.js: 1037 characters
|
||||
output.js: 1037 characters
|
||||
|
||||
<id> <size> <filename>
|
||||
<reason> from <filename>
|
||||
|
|
|
@ -5,12 +5,15 @@ var fs = require("fs");
|
|||
module.exports = function(template, filesReq, stdout, prefix) {
|
||||
|
||||
var regexp = new RegExp("\\{\\{" + (prefix ? prefix+":" : "") + "([^:\\}]+)\\}\\}", "g")
|
||||
var cwd = process.cwd();
|
||||
cwd = cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
cwd = new RegExp(cwd, "g");
|
||||
|
||||
return template.replace(regexp, function(match) {
|
||||
match = match.substr(2 + (prefix ? prefix.length+1 : 0), match.length - 4 - (prefix ? prefix.length+1 : 0));
|
||||
if(match === "stdout")
|
||||
return stdout;
|
||||
return filesReq("./" + match);
|
||||
});
|
||||
}).replace(cwd, ".");
|
||||
|
||||
}
|
Loading…
Reference in New Issue