2012-03-27 06:00:51 +08:00
|
|
|
# example.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
// Polyfill require for node.js usage of loaders
|
|
|
|
require = require("../../require-polyfill")(require.valueOf());
|
|
|
|
|
|
|
|
// use our loader
|
|
|
|
console.dir(require("./loader!./file"));
|
|
|
|
|
|
|
|
// use buildin json loader
|
|
|
|
console.dir(require("./test.json")); // default by extension
|
|
|
|
console.dir(require("json!./test.json")); // manual
|
|
|
|
```
|
|
|
|
|
|
|
|
# file.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
exports.foo = "bar";
|
|
|
|
```
|
|
|
|
|
|
|
|
# loader.js
|
|
|
|
|
|
|
|
``` javascript
|
2012-04-05 21:08:49 +08:00
|
|
|
module.exports = function(content) {
|
|
|
|
return "exports.answer = 42;\n" + content;
|
2012-03-27 06:00:51 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# test.json
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
{
|
|
|
|
"foobar": 1234
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# js/output.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
/******/(function(modules) {
|
|
|
|
/******/ var installedModules = {};
|
|
|
|
/******/ 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;
|
|
|
|
/******/ }
|
2012-05-22 04:59:31 +08:00
|
|
|
/******/ require.e = function(chunkId, callback) {
|
2012-03-27 06:00:51 +08:00
|
|
|
/******/ callback(require);
|
|
|
|
/******/ };
|
2012-05-17 18:47:06 +08:00
|
|
|
/******/ require.modules = modules;
|
2012-07-11 23:53:46 +08:00
|
|
|
/******/ require.cache = installedModules;
|
2012-03-27 06:00:51 +08:00
|
|
|
/******/ return require(0);
|
|
|
|
/******/})
|
2012-08-07 04:19:15 +08:00
|
|
|
/******/({c:"",
|
2012-03-27 06:00:51 +08:00
|
|
|
/******/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-27 06:00:51 +08:00
|
|
|
// Polyfill require for node.js usage of loaders
|
2012-07-11 23:53:46 +08:00
|
|
|
require = require(/* ../../require-polyfill */5)(require.valueOf());
|
2012-03-27 06:00:51 +08:00
|
|
|
|
|
|
|
// use our loader
|
2012-04-05 20:59:01 +08:00
|
|
|
console.dir(require(/* ./loader!./file */3));
|
2012-03-27 06:00:51 +08:00
|
|
|
|
|
|
|
// use buildin json loader
|
2012-04-08 03:36:55 +08:00
|
|
|
console.dir(require(/* ./test.json */2)); // default by extension
|
|
|
|
console.dir(require(/* json!./test.json */2)); // manual
|
|
|
|
/******/ /* WEBPACK FREE VAR INJECTION */ }(require(/* __webpack_console */1)))
|
2012-03-27 06:00:51 +08:00
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/1: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\buildin\__webpack_console.js ***/
|
|
|
|
|
2012-08-07 04:19:15 +08:00
|
|
|
var console = (function() { return this["console"] || (this["window"] && this["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() {};
|
2012-07-19 18:03:56 +08:00
|
|
|
var times = {};
|
2012-04-05 20:59:01 +08:00
|
|
|
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);
|
|
|
|
};
|
2012-03-27 06:00:51 +08:00
|
|
|
|
2012-04-08 03:36:55 +08:00
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/2: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\~\json-loader!.\test.json ***/
|
|
|
|
|
2012-04-08 03:36:55 +08:00
|
|
|
module.exports = {
|
|
|
|
"foobar": 1234
|
|
|
|
}
|
|
|
|
|
2012-03-27 06:00:51 +08:00
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/3: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** .\loader.js!.\file.js ***/
|
|
|
|
|
2012-04-05 21:08:49 +08:00
|
|
|
exports.answer = 42;
|
|
|
|
exports.foo = "bar";
|
2012-03-27 06:00:51 +08:00
|
|
|
|
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/4: function(module, exports, require) {
|
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/*** (webpack)\~\enhanced-require\index.webpack.js ***/
|
|
|
|
|
2012-04-08 03:36:55 +08:00
|
|
|
// No polyfill needed when compiled with webpack
|
|
|
|
module.exports = function(r){return r}
|
2012-03-27 06:00:51 +08:00
|
|
|
|
2012-07-11 23:53:46 +08:00
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/5: function(module, exports, require) {
|
|
|
|
|
|
|
|
/*** (webpack)\require-polyfill.js ***/
|
|
|
|
|
|
|
|
module.exports = require(/* enhanced-require */4)
|
|
|
|
|
2012-03-27 06:00:51 +08:00
|
|
|
/******/},
|
|
|
|
/******/
|
|
|
|
/******/})
|
|
|
|
```
|
|
|
|
|
2012-03-27 10:23:11 +08:00
|
|
|
# Console output
|
|
|
|
|
|
|
|
Prints in node.js (`node example.js`) and in browser:
|
|
|
|
|
|
|
|
```
|
|
|
|
{ answer: 42, foo: 'bar' }
|
|
|
|
{ foobar: 1234 }
|
|
|
|
{ foobar: 1234 }
|
|
|
|
```
|
|
|
|
|
2012-03-27 06:00:51 +08:00
|
|
|
# Info
|
|
|
|
|
|
|
|
## Uncompressed
|
|
|
|
|
|
|
|
```
|
2012-08-07 04:19:15 +08:00
|
|
|
Hash: 32d984116944fa5f4cb96f98c59402f4
|
|
|
|
Compile Time: 66ms
|
2012-03-27 06:00:51 +08:00
|
|
|
Chunks: 1
|
2012-07-11 23:53:46 +08:00
|
|
|
Modules: 6
|
|
|
|
Modules including duplicates: 6
|
|
|
|
Modules per chunk: 6
|
|
|
|
Modules first chunk: 6
|
2012-08-07 04:19:15 +08:00
|
|
|
output.js: 2610 characters
|
2012-04-08 03:36:55 +08:00
|
|
|
|
|
|
|
<id> <size> <filename>
|
|
|
|
<reason> from <filename>
|
2012-03-27 06:00:51 +08:00
|
|
|
output.js
|
2012-05-22 04:59:31 +08:00
|
|
|
0 333 .\example.js
|
2012-03-27 06:00:51 +08:00
|
|
|
main
|
2012-08-07 04:19:15 +08:00
|
|
|
1 516 (webpack)\buildin\__webpack_console.js
|
2012-04-05 20:59:01 +08:00
|
|
|
require (3x) from .\example.js
|
2012-05-07 03:07:24 +08:00
|
|
|
2 36 (webpack)\~\json-loader!.\test.json
|
2012-04-08 03:36:55 +08:00
|
|
|
require (1x) from .\example.js
|
2012-04-05 20:59:01 +08:00
|
|
|
require (1x) from .\example.js
|
2012-05-07 03:07:24 +08:00
|
|
|
3 41 .\loader.js!.\file.js
|
2012-04-05 20:59:01 +08:00
|
|
|
require (1x) from .\example.js
|
2012-07-11 23:53:46 +08:00
|
|
|
4 87 (webpack)\~\enhanced-require\index.webpack.js
|
|
|
|
require (1x) from (webpack)\require-polyfill.js
|
|
|
|
5 49 (webpack)\require-polyfill.js
|
2012-04-05 20:59:01 +08:00
|
|
|
require (1x) from .\example.js
|
2012-03-27 06:00:51 +08:00
|
|
|
```
|