2012-03-27 06:00:51 +08:00
|
|
|
# example.js
|
|
|
|
|
2019-04-09 02:29:40 +08:00
|
|
|
```javascript
|
2012-03-27 06:00:51 +08:00
|
|
|
// use our loader
|
|
|
|
console.dir(require("./loader!./file"));
|
|
|
|
|
2016-12-07 18:44:12 +08:00
|
|
|
// use buildin css loader
|
|
|
|
console.dir(require("./test.css")); // default by extension
|
|
|
|
console.dir(require("!css-loader!./test.css")); // manual
|
2012-03-27 06:00:51 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
# file.js
|
|
|
|
|
2019-04-09 02:29:40 +08:00
|
|
|
```javascript
|
2012-03-27 06:00:51 +08:00
|
|
|
exports.foo = "bar";
|
|
|
|
```
|
|
|
|
|
|
|
|
# loader.js
|
|
|
|
|
2019-04-09 02:29:40 +08:00
|
|
|
```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
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2016-12-07 18:44:12 +08:00
|
|
|
# test.css
|
2012-03-27 06:00:51 +08:00
|
|
|
|
2019-04-09 02:29:40 +08:00
|
|
|
```css
|
2016-12-07 18:44:12 +08:00
|
|
|
.some-class {
|
|
|
|
color: hotpink;
|
2012-03-27 06:00:51 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-01-05 04:39:29 +08:00
|
|
|
# dist/output.js
|
2012-03-27 06:00:51 +08:00
|
|
|
|
2019-04-09 02:29:40 +08:00
|
|
|
```javascript
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ (() => { // webpackBootstrap
|
|
|
|
/******/ var __webpack_modules__ = ([
|
|
|
|
/* 0 */,
|
2017-12-14 17:58:03 +08:00
|
|
|
/* 1 */
|
2017-06-05 22:12:12 +08:00
|
|
|
/*!*****************************!*\
|
|
|
|
!*** ./loader.js!./file.js ***!
|
|
|
|
\*****************************/
|
2019-08-05 19:32:25 +08:00
|
|
|
/*! exports [maybe provided (runtime-defined)] [no usage info] */
|
2018-12-19 21:05:17 +08:00
|
|
|
/*! runtime requirements: __webpack_exports__ */
|
2019-10-11 05:11:05 +08:00
|
|
|
/***/ ((__unused_webpack_module, exports) => {
|
2017-06-05 22:12:12 +08:00
|
|
|
|
|
|
|
exports.answer = 42;
|
|
|
|
exports.foo = "bar";
|
|
|
|
|
2017-12-14 17:58:03 +08:00
|
|
|
/***/ }),
|
|
|
|
/* 2 */
|
2019-04-04 04:48:54 +08:00
|
|
|
/*!****************************************************************!*\
|
|
|
|
!*** (webpack)/node_modules/css-loader/dist/cjs.js!./test.css ***!
|
|
|
|
\****************************************************************/
|
2019-08-05 19:32:25 +08:00
|
|
|
/*! exports [maybe provided (runtime-defined)] [no usage info] */
|
2019-11-15 07:06:30 +08:00
|
|
|
/*! runtime requirements: __webpack_require__, module, __webpack_exports__ */
|
2019-10-09 05:45:47 +08:00
|
|
|
/***/ ((module, exports, __webpack_require__) => {
|
2017-12-14 17:58:03 +08:00
|
|
|
|
2019-04-04 04:48:54 +08:00
|
|
|
exports = module.exports = __webpack_require__(/*! ../../node_modules/css-loader/dist/runtime/api.js */ 3)(false);
|
|
|
|
// Module
|
2018-09-25 23:08:35 +08:00
|
|
|
exports.push([module.i, ".some-class {\n\tcolor: hotpink;\n}\n", ""]);
|
2017-12-14 17:58:03 +08:00
|
|
|
|
|
|
|
|
2017-03-31 02:25:01 +08:00
|
|
|
/***/ }),
|
|
|
|
/* 3 */
|
2019-04-04 04:48:54 +08:00
|
|
|
/*!*************************************************************!*\
|
|
|
|
!*** (webpack)/node_modules/css-loader/dist/runtime/api.js ***!
|
|
|
|
\*************************************************************/
|
2019-08-05 19:32:25 +08:00
|
|
|
/*! exports [maybe provided (runtime-defined)] [no usage info] */
|
2018-12-19 21:05:17 +08:00
|
|
|
/*! runtime requirements: module */
|
2019-10-09 05:45:47 +08:00
|
|
|
/***/ ((module) => {
|
2016-12-14 19:03:24 +08:00
|
|
|
|
2019-04-04 04:48:54 +08:00
|
|
|
"use strict";
|
|
|
|
|
2016-12-14 19:03:24 +08:00
|
|
|
|
|
|
|
/*
|
2019-04-04 04:48:54 +08:00
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
2016-12-14 19:03:24 +08:00
|
|
|
*/
|
|
|
|
// css base code, injected by the css-loader
|
2019-10-09 05:45:47 +08:00
|
|
|
// eslint-disable-next-line func-names
|
2019-04-04 04:48:54 +08:00
|
|
|
module.exports = function (useSourceMap) {
|
|
|
|
var list = []; // return the list of modules as css string
|
|
|
|
|
|
|
|
list.toString = function toString() {
|
|
|
|
return this.map(function (item) {
|
|
|
|
var content = cssWithMappingToString(item, useSourceMap);
|
|
|
|
|
|
|
|
if (item[2]) {
|
2019-10-09 05:45:47 +08:00
|
|
|
return "@media ".concat(item[2], "{").concat(content, "}");
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
2019-10-09 05:45:47 +08:00
|
|
|
|
|
|
|
return content;
|
2019-04-04 04:48:54 +08:00
|
|
|
}).join('');
|
|
|
|
}; // import a list of modules into the list
|
2019-10-09 05:45:47 +08:00
|
|
|
// eslint-disable-next-line func-names
|
2019-04-04 04:48:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
list.i = function (modules, mediaQuery) {
|
|
|
|
if (typeof modules === 'string') {
|
2019-10-09 05:45:47 +08:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2019-04-04 04:48:54 +08:00
|
|
|
modules = [[null, modules, '']];
|
|
|
|
}
|
|
|
|
|
|
|
|
var alreadyImportedModules = {};
|
|
|
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
2019-10-09 05:45:47 +08:00
|
|
|
// eslint-disable-next-line prefer-destructuring
|
2019-04-04 04:48:54 +08:00
|
|
|
var id = this[i][0];
|
|
|
|
|
|
|
|
if (id != null) {
|
|
|
|
alreadyImportedModules[id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 05:45:47 +08:00
|
|
|
for (var _i = 0; _i < modules.length; _i++) {
|
|
|
|
var item = modules[_i]; // skip already imported module
|
2019-04-04 04:48:54 +08:00
|
|
|
// this implementation is not 100% perfect for weird media query combinations
|
|
|
|
// when a module is imported multiple times with different media queries.
|
|
|
|
// I hope this will never occur (Hey this way we have smaller bundles)
|
|
|
|
|
|
|
|
if (item[0] == null || !alreadyImportedModules[item[0]]) {
|
|
|
|
if (mediaQuery && !item[2]) {
|
|
|
|
item[2] = mediaQuery;
|
|
|
|
} else if (mediaQuery) {
|
2019-10-09 05:45:47 +08:00
|
|
|
item[2] = "(".concat(item[2], ") and (").concat(mediaQuery, ")");
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
list.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return list;
|
2016-12-14 19:03:24 +08:00
|
|
|
};
|
|
|
|
|
2017-06-05 22:12:12 +08:00
|
|
|
function cssWithMappingToString(item, useSourceMap) {
|
2019-10-09 05:45:47 +08:00
|
|
|
var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring
|
|
|
|
|
2019-04-04 04:48:54 +08:00
|
|
|
var cssMapping = item[3];
|
2017-06-05 22:12:12 +08:00
|
|
|
|
2019-04-04 04:48:54 +08:00
|
|
|
if (!cssMapping) {
|
|
|
|
return content;
|
|
|
|
}
|
2017-06-05 22:12:12 +08:00
|
|
|
|
2019-04-04 04:48:54 +08:00
|
|
|
if (useSourceMap && typeof btoa === 'function') {
|
|
|
|
var sourceMapping = toComment(cssMapping);
|
|
|
|
var sourceURLs = cssMapping.sources.map(function (source) {
|
2019-10-09 05:45:47 +08:00
|
|
|
return "/*# sourceURL=".concat(cssMapping.sourceRoot).concat(source, " */");
|
2019-04-04 04:48:54 +08:00
|
|
|
});
|
|
|
|
return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [content].join('\n');
|
|
|
|
} // Adapted from convert-source-map (MIT)
|
2017-06-05 22:12:12 +08:00
|
|
|
|
|
|
|
|
2019-04-04 04:48:54 +08:00
|
|
|
function toComment(sourceMap) {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
|
2019-10-09 05:45:47 +08:00
|
|
|
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
|
|
|
|
return "/*# ".concat(data, " */");
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
2016-12-14 19:03:24 +08:00
|
|
|
|
2017-03-31 02:25:01 +08:00
|
|
|
/***/ })
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ ]);
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ // The module cache
|
|
|
|
/******/ var __webpack_module_cache__ = {};
|
|
|
|
/******/
|
|
|
|
/******/ // The require function
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
|
|
|
/******/ // Check if module is in cache
|
|
|
|
/******/ if(__webpack_module_cache__[moduleId]) {
|
|
|
|
/******/ return __webpack_module_cache__[moduleId].exports;
|
|
|
|
/******/ }
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
|
|
/******/ i: moduleId,
|
|
|
|
/******/ l: false,
|
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
|
|
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
|
|
/******/
|
|
|
|
/******/ // Flag the module as loaded
|
|
|
|
/******/ module.l = true;
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
!function() {
|
|
|
|
/*!********************!*\
|
|
|
|
!*** ./example.js ***!
|
|
|
|
\********************/
|
|
|
|
/*! exports [maybe provided (runtime-defined)] [no usage info] */
|
|
|
|
/*! runtime requirements: __webpack_require__ */
|
|
|
|
// use our loader
|
|
|
|
console.dir(__webpack_require__(/*! ./loader!./file */ 1));
|
|
|
|
|
|
|
|
// use buildin css loader
|
|
|
|
console.dir(__webpack_require__(/*! ./test.css */ 2)); // default by extension
|
|
|
|
console.dir(__webpack_require__(/*! css-loader!./test.css */ 2)); // manual
|
|
|
|
|
|
|
|
}();
|
|
|
|
/******/ })()
|
|
|
|
;
|
2012-03-27 06:00:51 +08:00
|
|
|
```
|
|
|
|
|
2012-03-27 10:23:11 +08:00
|
|
|
# Console output
|
|
|
|
|
2013-02-24 09:27:11 +08:00
|
|
|
Prints in node.js (`enhanced-require example.js`) and in browser:
|
2012-03-27 10:23:11 +08:00
|
|
|
|
|
|
|
```
|
|
|
|
{ answer: 42, foo: 'bar' }
|
|
|
|
{ foobar: 1234 }
|
|
|
|
{ foobar: 1234 }
|
|
|
|
```
|
|
|
|
|
2012-03-27 06:00:51 +08:00
|
|
|
# Info
|
|
|
|
|
2017-12-14 17:58:03 +08:00
|
|
|
## Unoptimized
|
2012-03-27 06:00:51 +08:00
|
|
|
|
|
|
|
```
|
2017-12-14 17:58:03 +08:00
|
|
|
Hash: 0a1b2c3d4e5f6a7b8c9d
|
2019-11-15 07:06:30 +08:00
|
|
|
Version: webpack 5.0.0-beta.6
|
2019-10-11 05:11:05 +08:00
|
|
|
Asset Size
|
|
|
|
output.js 5.46 KiB [emitted] [name: main]
|
2016-09-07 18:28:56 +08:00
|
|
|
Entrypoint main = output.js
|
2019-10-11 05:11:05 +08:00
|
|
|
chunk output.js (main) 3.03 KiB [entry] [rendered]
|
2019-01-25 20:15:22 +08:00
|
|
|
> ./example.js main
|
2019-10-11 05:11:05 +08:00
|
|
|
(webpack)/node_modules/css-loader/dist/cjs.js!./test.css 178 bytes [built]
|
2018-09-26 05:13:58 +08:00
|
|
|
[used exports unknown]
|
2019-10-11 05:11:05 +08:00
|
|
|
cjs require ./test.css ./example.js 5:12-33
|
|
|
|
cjs require !css-loader!./test.css ./example.js 6:12-45
|
|
|
|
(webpack)/node_modules/css-loader/dist/runtime/api.js 2.61 KiB [built]
|
2018-09-26 05:13:58 +08:00
|
|
|
[used exports unknown]
|
2019-10-11 05:11:05 +08:00
|
|
|
cjs require ../../node_modules/css-loader/dist/runtime/api.js (webpack)/node_modules/css-loader/dist/cjs.js!./test.css 1:27-87
|
|
|
|
./example.js 204 bytes [built]
|
2018-09-26 05:13:58 +08:00
|
|
|
[used exports unknown]
|
2019-10-11 05:11:05 +08:00
|
|
|
entry ./example.js main
|
|
|
|
./loader.js!./file.js 41 bytes [built]
|
2018-12-19 21:05:17 +08:00
|
|
|
[used exports unknown]
|
2019-10-11 05:11:05 +08:00
|
|
|
cjs require ./loader!./file ./example.js 2:12-38
|
2013-12-16 06:30:50 +08:00
|
|
|
```
|
|
|
|
|
2017-12-14 17:58:03 +08:00
|
|
|
## Production mode
|
2013-12-16 06:30:50 +08:00
|
|
|
|
|
|
|
```
|
2017-12-14 17:58:03 +08:00
|
|
|
Hash: 0a1b2c3d4e5f6a7b8c9d
|
2019-11-15 07:06:30 +08:00
|
|
|
Version: webpack 5.0.0-beta.6
|
2019-10-11 05:11:05 +08:00
|
|
|
Asset Size
|
2019-10-28 21:09:53 +08:00
|
|
|
output.js 1.18 KiB [emitted] [name: main]
|
2016-09-07 18:28:56 +08:00
|
|
|
Entrypoint main = output.js
|
2019-10-11 05:11:05 +08:00
|
|
|
chunk output.js (main) 3.03 KiB [entry] [rendered]
|
2019-01-25 20:15:22 +08:00
|
|
|
> ./example.js main
|
2019-10-11 05:11:05 +08:00
|
|
|
(webpack)/node_modules/css-loader/dist/cjs.js!./test.css 178 bytes [built]
|
|
|
|
cjs require ./test.css ./example.js 5:12-33
|
|
|
|
cjs require !css-loader!./test.css ./example.js 6:12-45
|
|
|
|
(webpack)/node_modules/css-loader/dist/runtime/api.js 2.61 KiB [built]
|
|
|
|
cjs require ../../node_modules/css-loader/dist/runtime/api.js (webpack)/node_modules/css-loader/dist/cjs.js!./test.css 1:27-87
|
|
|
|
./example.js 204 bytes [built]
|
|
|
|
[no exports used]
|
|
|
|
entry ./example.js main
|
|
|
|
./loader.js!./file.js 41 bytes [built]
|
|
|
|
cjs require ./loader!./file ./example.js 2:12-38
|
2013-12-16 06:30:50 +08:00
|
|
|
```
|