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"));
|
|
|
|
|
2020-03-13 00:51:26 +08:00
|
|
|
// use built-in css loader
|
2016-12-07 18:44:12 +08:00
|
|
|
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 ***!
|
|
|
|
\*****************************/
|
2020-05-21 05:26:51 +08:00
|
|
|
/*! default exports */
|
2020-09-21 04:39:12 +08:00
|
|
|
/*! export answer [provided] [no usage info] [missing usage info prevents renaming] */
|
|
|
|
/*! export foo [provided] [no usage info] [missing usage info prevents renaming] */
|
|
|
|
/*! other exports [not provided] [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 */
|
2020-05-21 05:26:51 +08:00
|
|
|
/*!************************************************************!*\
|
|
|
|
!*** ../../node_modules/css-loader/dist/cjs.js!./test.css ***!
|
|
|
|
\************************************************************/
|
2021-08-20 14:12:50 +08:00
|
|
|
/*! namespace exports */
|
|
|
|
/*! export default [provided] [no usage info] [missing usage info prevents renaming] */
|
|
|
|
/*! other exports [not provided] [no usage info] */
|
|
|
|
/*! runtime requirements: __webpack_require__, __webpack_require__.n, __webpack_exports__, __webpack_require__.r, module.id, __webpack_require__.d, __webpack_require__.*, module */
|
|
|
|
/***/ ((module, __webpack_exports__, __webpack_require__) => {
|
2017-12-14 17:58:03 +08:00
|
|
|
|
2021-08-20 14:12:50 +08:00
|
|
|
"use strict";
|
|
|
|
__webpack_require__.r(__webpack_exports__);
|
|
|
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
|
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
|
|
/* harmony export */ });
|
|
|
|
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../node_modules/css-loader/dist/runtime/api.js */ 3);
|
|
|
|
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0__);
|
2020-05-21 05:26:51 +08:00
|
|
|
// Imports
|
2021-08-20 14:12:50 +08:00
|
|
|
|
|
|
|
var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0___default()(function(i){return i[1]});
|
2019-04-04 04:48:54 +08:00
|
|
|
// Module
|
2021-08-20 14:12:50 +08:00
|
|
|
___CSS_LOADER_EXPORT___.push([module.id, ".some-class {\n\tcolor: hotpink;\n}\n", ""]);
|
2020-05-21 05:26:51 +08:00
|
|
|
// Exports
|
2021-08-20 14:12:50 +08:00
|
|
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___);
|
2017-12-14 17:58:03 +08:00
|
|
|
|
|
|
|
|
2017-03-31 02:25:01 +08:00
|
|
|
/***/ }),
|
|
|
|
/* 3 */
|
2020-05-21 05:26:51 +08:00
|
|
|
/*!*********************************************************!*\
|
|
|
|
!*** ../../node_modules/css-loader/dist/runtime/api.js ***!
|
|
|
|
\*********************************************************/
|
|
|
|
/*! unknown exports (runtime-defined) */
|
2018-12-19 21:05:17 +08:00
|
|
|
/*! runtime requirements: module */
|
2020-09-21 04:39:12 +08:00
|
|
|
/*! CommonJS bailout: module.exports is used directly at 9:0-14 */
|
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
|
2021-08-20 14:12:50 +08:00
|
|
|
module.exports = function (cssWithMappingToString) {
|
2019-04-04 04:48:54 +08:00
|
|
|
var list = []; // return the list of modules as css string
|
|
|
|
|
|
|
|
list.toString = function toString() {
|
|
|
|
return this.map(function (item) {
|
2021-08-20 14:12:50 +08:00
|
|
|
var content = cssWithMappingToString(item);
|
2019-04-04 04:48:54 +08:00
|
|
|
|
|
|
|
if (item[2]) {
|
2020-05-21 05:26:51 +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;
|
2021-08-20 14:12:50 +08:00
|
|
|
}).join("");
|
2019-04-04 04:48:54 +08:00
|
|
|
}; // 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
|
|
|
|
|
|
|
|
2020-05-21 05:26:51 +08:00
|
|
|
list.i = function (modules, mediaQuery, dedupe) {
|
2021-08-20 14:12:50 +08:00
|
|
|
if (typeof modules === "string") {
|
2019-10-09 05:45:47 +08:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2021-08-20 14:12:50 +08:00
|
|
|
modules = [[null, modules, ""]];
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var alreadyImportedModules = {};
|
|
|
|
|
2020-05-21 05:26:51 +08:00
|
|
|
if (dedupe) {
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
// eslint-disable-next-line prefer-destructuring
|
|
|
|
var id = this[i][0];
|
2019-04-04 04:48:54 +08:00
|
|
|
|
2020-05-21 05:26:51 +08:00
|
|
|
if (id != null) {
|
|
|
|
alreadyImportedModules[id] = true;
|
|
|
|
}
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 05:45:47 +08:00
|
|
|
for (var _i = 0; _i < modules.length; _i++) {
|
2020-05-21 05:26:51 +08:00
|
|
|
var item = [].concat(modules[_i]);
|
|
|
|
|
|
|
|
if (dedupe && alreadyImportedModules[item[0]]) {
|
|
|
|
// eslint-disable-next-line no-continue
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-04 04:48:54 +08:00
|
|
|
|
2020-05-21 05:26:51 +08:00
|
|
|
if (mediaQuery) {
|
|
|
|
if (!item[2]) {
|
2019-04-04 04:48:54 +08:00
|
|
|
item[2] = mediaQuery;
|
2020-05-21 05:26:51 +08:00
|
|
|
} else {
|
|
|
|
item[2] = "".concat(mediaQuery, " and ").concat(item[2]);
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
|
|
|
}
|
2020-05-21 05:26:51 +08:00
|
|
|
|
|
|
|
list.push(item);
|
2019-04-04 04:48:54 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return list;
|
2016-12-14 19:03:24 +08:00
|
|
|
};
|
|
|
|
|
2017-03-31 02:25:01 +08:00
|
|
|
/***/ })
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ ]);
|
2019-11-19 21:10:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
<details><summary><code>/* webpack runtime code */</code></summary>
|
|
|
|
|
|
|
|
``` js
|
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
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
|
|
/******/ if (cachedModule !== undefined) {
|
|
|
|
/******/ return cachedModule.exports;
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ }
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
2020-05-21 05:26:51 +08:00
|
|
|
/******/ id: moduleId,
|
|
|
|
/******/ // no module.loaded needed
|
2019-10-11 05:11:05 +08:00
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
|
|
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ /* webpack/runtime/compat get default export */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
|
|
/******/ __webpack_require__.n = (module) => {
|
|
|
|
/******/ var getter = module && module.__esModule ?
|
|
|
|
/******/ () => (module['default']) :
|
|
|
|
/******/ () => (module);
|
|
|
|
/******/ __webpack_require__.d(getter, { a: getter });
|
|
|
|
/******/ return getter;
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // define getter functions for harmony exports
|
|
|
|
/******/ __webpack_require__.d = (exports, definition) => {
|
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/make namespace object */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // define __esModule on exports
|
|
|
|
/******/ __webpack_require__.r = (exports) => {
|
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
2019-11-19 21:10:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
``` js
|
2021-08-20 14:12:50 +08:00
|
|
|
var __webpack_exports__ = {};
|
|
|
|
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
2020-05-21 05:26:51 +08:00
|
|
|
(() => {
|
2019-10-11 05:11:05 +08:00
|
|
|
/*!********************!*\
|
|
|
|
!*** ./example.js ***!
|
|
|
|
\********************/
|
2020-05-21 05:26:51 +08:00
|
|
|
/*! unknown exports (runtime-defined) */
|
2019-10-11 05:11:05 +08:00
|
|
|
/*! runtime requirements: __webpack_require__ */
|
|
|
|
// use our loader
|
|
|
|
console.dir(__webpack_require__(/*! ./loader!./file */ 1));
|
|
|
|
|
2020-03-13 00:51:26 +08:00
|
|
|
// use built-in css loader
|
2019-10-11 05:11:05 +08:00
|
|
|
console.dir(__webpack_require__(/*! ./test.css */ 2)); // default by extension
|
2020-05-21 05:26:51 +08:00
|
|
|
console.dir(__webpack_require__(/*! !css-loader!./test.css */ 2)); // manual
|
|
|
|
|
|
|
|
})();
|
2019-10-11 05:11:05 +08:00
|
|
|
|
|
|
|
/******/ })()
|
|
|
|
;
|
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
|
|
|
|
|
|
|
```
|
2021-08-20 14:12:50 +08:00
|
|
|
asset output.js 7.31 KiB [emitted] (name: main)
|
|
|
|
chunk (runtime: main) output.js (main) 2.14 KiB (javascript) 937 bytes (runtime) [entry] [rendered]
|
2020-09-21 04:39:12 +08:00
|
|
|
> ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
runtime modules 937 bytes 4 modules
|
|
|
|
dependent modules 1.94 KiB [dependent] 3 modules
|
2020-09-21 04:39:12 +08:00
|
|
|
./example.js 205 bytes [built] [code generated]
|
|
|
|
[used exports unknown]
|
|
|
|
entry ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
webpack 5.51.1 compiled successfully
|
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
|
|
|
|
|
|
|
```
|
2021-08-20 14:12:50 +08:00
|
|
|
asset output.js 1.25 KiB [emitted] [minimized] (name: main)
|
|
|
|
chunk (runtime: main) output.js (main) 2.14 KiB (javascript) 937 bytes (runtime) [entry] [rendered]
|
2020-09-21 04:39:12 +08:00
|
|
|
> ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
runtime modules 937 bytes 4 modules
|
|
|
|
dependent modules 1.94 KiB [dependent] 3 modules
|
2020-09-21 04:39:12 +08:00
|
|
|
./example.js 205 bytes [built] [code generated]
|
|
|
|
[no exports used]
|
|
|
|
entry ./example.js main
|
2021-08-20 14:12:50 +08:00
|
|
|
webpack 5.51.1 compiled successfully
|
2013-12-16 06:30:50 +08:00
|
|
|
```
|