2012-03-27 06:00:51 +08:00
|
|
|
# example.js
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
// Polyfill require for node.js usage of loaders
|
2012-10-25 01:28:17 +08:00
|
|
|
require = require("enhanced-require")(module);
|
2012-03-27 06:00:51 +08:00
|
|
|
|
|
|
|
// 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
|
2013-01-31 01:49:25 +08:00
|
|
|
/******/ (function webpackBootstrap(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: {},
|
|
|
|
/******/ id: moduleId,
|
|
|
|
/******/ loaded: false
|
|
|
|
/******/ };
|
|
|
|
/******/ modules[moduleId].call(null, module, module.exports, require);
|
|
|
|
/******/ module.loaded = true;
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/ require.e = function requireEnsure(chunkId, callback) {
|
|
|
|
/******/ callback.call(null, require);
|
|
|
|
/******/ };
|
|
|
|
/******/ require.modules = modules;
|
|
|
|
/******/ require.cache = installedModules;
|
|
|
|
/******/ return require(0);
|
|
|
|
/******/ })({
|
|
|
|
/******/ c: "",
|
|
|
|
|
|
|
|
/***/ 0:
|
|
|
|
/*!********************!*\
|
|
|
|
!*** ./example.js ***!
|
|
|
|
\********************/
|
|
|
|
/***/ function(module, exports, require) {
|
|
|
|
|
|
|
|
/* WEBPACK VAR INJECTION */(function(module) {// Polyfill require for node.js usage of loaders
|
|
|
|
require = require(/*! enhanced-require */ 3)(module);
|
|
|
|
|
|
|
|
// use our loader
|
|
|
|
console.dir(require(/*! ./loader!./file */ 4));
|
|
|
|
|
|
|
|
// use buildin json loader
|
|
|
|
console.dir(require((function webpackMissingModule() { throw new Error("Cannot find module \"./test.json\""); }()))); // default by extension
|
|
|
|
console.dir(require(/*! json!./test.json */ 1)); // manual
|
|
|
|
/* WEBPACK VAR INJECTION */}(require(/*! (webpack)/buildin/module.js */ 2)(module)))
|
|
|
|
|
|
|
|
/***/ },
|
|
|
|
|
|
|
|
/***/ 1:
|
2013-01-31 10:25:20 +08:00
|
|
|
/*!************************************************************************************!*\
|
|
|
|
!*** C:/Users/Sokrates/Eigene Repos/webpack-development/~/json-loader!./test.json ***!
|
|
|
|
\************************************************************************************/
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ function(module, exports, require) {
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"foobar": 1234
|
2012-10-25 01:28:17 +08:00
|
|
|
}
|
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ },
|
|
|
|
|
|
|
|
/***/ 2:
|
|
|
|
/*!***********************************!*\
|
|
|
|
!*** (webpack)/buildin/module.js ***!
|
|
|
|
\***********************************/
|
|
|
|
/***/ function(module, exports, require) {
|
|
|
|
|
|
|
|
module.exports = function(module) {
|
|
|
|
if(!module.webpackPolyfill) {
|
|
|
|
module.deprecate = function() {};
|
|
|
|
module.paths = [];
|
|
|
|
// module.parent = undefined by default
|
|
|
|
module.children = [];
|
|
|
|
module.webpackPolyfill = 1;
|
|
|
|
}
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
2012-10-26 21:07:50 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ },
|
2012-10-26 21:07:50 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ 3:
|
|
|
|
/*!*******************************************!*\
|
|
|
|
!*** (webpack)/buildin/return-require.js ***!
|
|
|
|
\*******************************************/
|
|
|
|
/***/ function(module, exports, require) {
|
2012-10-26 21:07:50 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
module.exports = function() { return require; };
|
2012-07-11 23:53:46 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ },
|
2012-03-27 06:00:51 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ 4:
|
|
|
|
/*!*****************************!*\
|
|
|
|
!*** ./loader.js!./file.js ***!
|
|
|
|
\*****************************/
|
|
|
|
/***/ function(module, exports, require) {
|
2012-11-07 19:49:01 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
exports.answer = 42;
|
|
|
|
exports.foo = "bar";
|
2012-11-07 19:49:01 +08:00
|
|
|
|
2013-01-31 01:49:25 +08:00
|
|
|
/***/ }
|
|
|
|
/******/ })
|
2012-11-07 19:49:01 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
```
|
2013-01-31 10:25:20 +08:00
|
|
|
Hash: 62f35121ae16eff2526b8ac568437057
|
|
|
|
Time: 52ms
|
2013-01-31 01:49:25 +08:00
|
|
|
Asset Size Chunks Chunk Names
|
2013-01-31 10:25:20 +08:00
|
|
|
output.js 2853 0 main
|
|
|
|
chunk {0} output.js (main) 692
|
|
|
|
[0] ./example.js 304 [built] {0}
|
|
|
|
[1] C:/Users/Sokrates/Eigene Repos/webpack-development/~/json-loader!./test.json 36 [built] {0}
|
2013-01-31 01:49:25 +08:00
|
|
|
cjs require json!./test.json [0] ./example.js 9:12-39
|
2013-01-31 10:25:20 +08:00
|
|
|
[2] (webpack)/buildin/module.js 251 [built] {0}
|
|
|
|
cjs require module [0] ./example.js 1:0-108
|
2013-01-31 01:49:25 +08:00
|
|
|
[3] (webpack)/buildin/return-require.js 60 [built] {0}
|
|
|
|
cjs require enhanced-require [0] ./example.js 2:10-37
|
|
|
|
[4] ./loader.js!./file.js 41 [not cacheable] [built] {0}
|
|
|
|
cjs require ./loader!./file [0] ./example.js 5:12-38
|
|
|
|
|
|
|
|
ERROR in .\test.json
|
|
|
|
Module parse failed: .\test.json Line 2: Unexpected token :
|
|
|
|
{
|
|
|
|
"foobar": 1234
|
|
|
|
}
|
|
|
|
@ ./example.js 8:12-34
|
2012-03-27 06:00:51 +08:00
|
|
|
```
|