cc4f8345fa | ||
---|---|---|
.. | ||
README.md | ||
build.js | ||
enhanced-require.config.js | ||
example.js | ||
file.js | ||
loader.js | ||
template.md | ||
test.json | ||
webpack.config.js |
README.md
example.js
// 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
exports.foo = "bar";
loader.js
module.exports = function(content) {
return "exports.answer = 42;\n" + content;
}
test.json
{
"foobar": 1234
}
js/output.js
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function require(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(null, module, module.exports, require);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // The bundle contains no chunks. A empty chunk loading function.
/******/ require.e = function requireEnsure(_, callback) {
/******/ callback.call(null, require);
/******/ };
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ require.modules = modules;
/******/
/******/ // expose the module cache
/******/ require.cache = installedModules;
/******/
/******/
/******/ // Load entry module and return exports
/******/ return require(0);
/******/ })
/************************************************************************/
/******/ ({
/******/ // __webpack_public_path__
/******/ c: "",
/***/ 0:
/*!********************!*\
!*** ./example.js ***!
\********************/
/***/ function(module, exports, require) {
// use our loader
console.dir(require(/*! ./loader!./file */ 2));
// use buildin json loader
console.dir(require(/*! ./test.json */ 1)); // default by extension
console.dir(require(/*! json!./test.json */ 1)); // manual
/***/ },
/***/ 1:
/*!***********************************************************************************************************!*\
!*** (webpack)/~/json-loader!./test.json ***!
\***********************************************************************************************************/
/***/ function(module, exports, require) {
module.exports = {
"foobar": 1234
}
/***/ },
/***/ 2:
/*!*****************************!*\
!*** ./loader.js!./file.js ***!
\*****************************/
/***/ function(module, exports, require) {
exports.answer = 42;
exports.foo = "bar";
/***/ }
/******/ })
Console output
Prints in node.js (enhanced-require example.js
) and in browser:
{ answer: 42, foo: 'bar' }
{ foobar: 1234 }
{ foobar: 1234 }
Info
Uncompressed
Hash: a8ae2738f8417066d7fe12d977bf7fe4
Version: webpack 0.10.0-beta6
Time: 43ms
Asset Size Chunks Chunk Names
output.js 2564 0 [emitted] main
chunk {0} output.js (main) 277 [rendered]
[0] ./example.js 200 [built] {0}
[1] (webpack)/~/json-loader!./test.json 36 [built] {0}
cjs require ./test.json [0] ./example.js 5:12-34
cjs require !json!./test.json [0] ./example.js 6:12-40
[2] ./loader.js!./file.js 41 [not cacheable] [built] {0}
cjs require ./loader!./file [0] ./example.js 2:12-38