| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 | var _path = _interopRequireDefault(require("path"));
|
|---|
| 8 | var _utils = require("./utils");
|
|---|
| 9 | var _options = _interopRequireDefault(require("./options.json"));
|
|---|
| 10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|---|
| 11 | // eslint-disable-next-line consistent-return
|
|---|
| 12 | const loader = function loader(content) {
|
|---|
| 13 | if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && (this._module.type === "css" || this._module.type === "css/global" || this._module.type === "css/module" || this._module.type === "css/auto")) {
|
|---|
| 14 | return content;
|
|---|
| 15 | }
|
|---|
| 16 | };
|
|---|
| 17 | loader.pitch = function pitch(request) {
|
|---|
| 18 | if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && (this._module.type === "css" || this._module.type === "css/global" || this._module.type === "css/module" || this._module.type === "css/auto")) {
|
|---|
| 19 | this.emitWarning(new Error('You can\'t use `experiments.css` (`experiments.futureDefaults` enable built-in CSS support by default) and `style-loader` together, please set `experiments.css` to `false` or set `{ type: "javascript/auto" }` for rules with `style-loader` in your webpack config (now `style-loader` does nothing).'));
|
|---|
| 20 | return;
|
|---|
| 21 | }
|
|---|
| 22 | const options = this.getOptions(_options.default);
|
|---|
| 23 | const injectType = options.injectType || "styleTag";
|
|---|
| 24 | const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
|
|---|
| 25 | const runtimeOptions = {};
|
|---|
| 26 | if (options.attributes) {
|
|---|
| 27 | runtimeOptions.attributes = options.attributes;
|
|---|
| 28 | }
|
|---|
| 29 | if (options.base) {
|
|---|
| 30 | runtimeOptions.base = options.base;
|
|---|
| 31 | }
|
|---|
| 32 | const insertType = typeof options.insert === "function" ? "function" : options.insert && _path.default.isAbsolute(options.insert) ? "module-path" : "selector";
|
|---|
| 33 | const styleTagTransformType = typeof options.styleTagTransform === "function" ? "function" : options.styleTagTransform && _path.default.isAbsolute(options.styleTagTransform) ? "module-path" : "default";
|
|---|
| 34 | switch (injectType) {
|
|---|
| 35 | case "linkTag":
|
|---|
| 36 | {
|
|---|
| 37 | const hmrCode = this.hot ? (0, _utils.getLinkHmrCode)(esModule, this, request) : "";
|
|---|
| 38 |
|
|---|
| 39 | // eslint-disable-next-line consistent-return
|
|---|
| 40 | return `
|
|---|
| 41 | ${(0, _utils.getImportLinkAPICode)(esModule, this)}
|
|---|
| 42 | ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
|
|---|
| 43 | ${(0, _utils.getImportLinkContentCode)(esModule, this, request)}
|
|---|
| 44 | ${esModule ? "" : `content = content.__esModule ? content.default : content;`}
|
|---|
| 45 |
|
|---|
| 46 | var options = ${JSON.stringify(runtimeOptions)};
|
|---|
| 47 |
|
|---|
| 48 | ${(0, _utils.getInsertOptionCode)(insertType, options)}
|
|---|
| 49 |
|
|---|
| 50 | var update = API(content, options);
|
|---|
| 51 |
|
|---|
| 52 | ${hmrCode}
|
|---|
| 53 |
|
|---|
| 54 | ${esModule ? "export default {}" : ""}`;
|
|---|
| 55 | }
|
|---|
| 56 | case "lazyStyleTag":
|
|---|
| 57 | case "lazyAutoStyleTag":
|
|---|
| 58 | case "lazySingletonStyleTag":
|
|---|
| 59 | {
|
|---|
| 60 | const isSingleton = injectType === "lazySingletonStyleTag";
|
|---|
| 61 | const isAuto = injectType === "lazyAutoStyleTag";
|
|---|
| 62 | const hmrCode = this.hot ? (0, _utils.getStyleHmrCode)(esModule, this, request, true) : "";
|
|---|
| 63 |
|
|---|
| 64 | // eslint-disable-next-line consistent-return
|
|---|
| 65 | return `
|
|---|
| 66 | var exported = {};
|
|---|
| 67 |
|
|---|
| 68 | ${(0, _utils.getImportStyleAPICode)(esModule, this)}
|
|---|
| 69 | ${(0, _utils.getImportStyleDomAPICode)(esModule, this, isSingleton, isAuto)}
|
|---|
| 70 | ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
|
|---|
| 71 | ${(0, _utils.getSetAttributesCode)(esModule, this, options)}
|
|---|
| 72 | ${(0, _utils.getImportInsertStyleElementCode)(esModule, this)}
|
|---|
| 73 | ${(0, _utils.getStyleTagTransformFnCode)(esModule, this, options, isSingleton, styleTagTransformType)}
|
|---|
| 74 | ${(0, _utils.getImportStyleContentCode)(esModule, this, request)}
|
|---|
| 75 | ${isAuto ? (0, _utils.getImportIsOldIECode)(esModule, this) : ""}
|
|---|
| 76 | ${esModule ? `if (content && content.locals) {
|
|---|
| 77 | exported.locals = content.locals;
|
|---|
| 78 | }
|
|---|
| 79 | ` : `content = content.__esModule ? content.default : content;
|
|---|
| 80 |
|
|---|
| 81 | exported.locals = content.locals || {};`}
|
|---|
| 82 |
|
|---|
| 83 | var refs = 0;
|
|---|
| 84 | var update;
|
|---|
| 85 | var options = ${JSON.stringify(runtimeOptions)};
|
|---|
| 86 |
|
|---|
| 87 | ${(0, _utils.getStyleTagTransformFn)(options, isSingleton)};
|
|---|
| 88 | options.setAttributes = setAttributes;
|
|---|
| 89 | ${(0, _utils.getInsertOptionCode)(insertType, options)}
|
|---|
| 90 | options.domAPI = ${(0, _utils.getdomAPI)(isAuto)};
|
|---|
| 91 | options.insertStyleElement = insertStyleElement;
|
|---|
| 92 |
|
|---|
| 93 | exported.use = function(insertOptions) {
|
|---|
| 94 | options.options = insertOptions || {};
|
|---|
| 95 |
|
|---|
| 96 | if (!(refs++)) {
|
|---|
| 97 | update = API(content, options);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | return exported;
|
|---|
| 101 | };
|
|---|
| 102 | exported.unuse = function() {
|
|---|
| 103 | if (refs > 0 && !--refs) {
|
|---|
| 104 | update();
|
|---|
| 105 | update = null;
|
|---|
| 106 | }
|
|---|
| 107 | };
|
|---|
| 108 |
|
|---|
| 109 | ${hmrCode}
|
|---|
| 110 |
|
|---|
| 111 | ${(0, _utils.getExportLazyStyleCode)(esModule, this, request)}
|
|---|
| 112 | `;
|
|---|
| 113 | }
|
|---|
| 114 | case "styleTag":
|
|---|
| 115 | case "autoStyleTag":
|
|---|
| 116 | case "singletonStyleTag":
|
|---|
| 117 | default:
|
|---|
| 118 | {
|
|---|
| 119 | const isSingleton = injectType === "singletonStyleTag";
|
|---|
| 120 | const isAuto = injectType === "autoStyleTag";
|
|---|
| 121 | const hmrCode = this.hot ? (0, _utils.getStyleHmrCode)(esModule, this, request, false) : "";
|
|---|
| 122 |
|
|---|
| 123 | // eslint-disable-next-line consistent-return
|
|---|
| 124 | return `
|
|---|
| 125 | ${(0, _utils.getImportStyleAPICode)(esModule, this)}
|
|---|
| 126 | ${(0, _utils.getImportStyleDomAPICode)(esModule, this, isSingleton, isAuto)}
|
|---|
| 127 | ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
|
|---|
| 128 | ${(0, _utils.getSetAttributesCode)(esModule, this, options)}
|
|---|
| 129 | ${(0, _utils.getImportInsertStyleElementCode)(esModule, this)}
|
|---|
| 130 | ${(0, _utils.getStyleTagTransformFnCode)(esModule, this, options, isSingleton, styleTagTransformType)}
|
|---|
| 131 | ${(0, _utils.getImportStyleContentCode)(esModule, this, request)}
|
|---|
| 132 | ${isAuto ? (0, _utils.getImportIsOldIECode)(esModule, this) : ""}
|
|---|
| 133 | ${esModule ? "" : `content = content.__esModule ? content.default : content;`}
|
|---|
| 134 |
|
|---|
| 135 | var options = ${JSON.stringify(runtimeOptions)};
|
|---|
| 136 |
|
|---|
| 137 | ${(0, _utils.getStyleTagTransformFn)(options, isSingleton)};
|
|---|
| 138 | options.setAttributes = setAttributes;
|
|---|
| 139 | ${(0, _utils.getInsertOptionCode)(insertType, options)}
|
|---|
| 140 | options.domAPI = ${(0, _utils.getdomAPI)(isAuto)};
|
|---|
| 141 | options.insertStyleElement = insertStyleElement;
|
|---|
| 142 |
|
|---|
| 143 | var update = API(content, options);
|
|---|
| 144 |
|
|---|
| 145 | ${hmrCode}
|
|---|
| 146 |
|
|---|
| 147 | ${(0, _utils.getExportStyleCode)(esModule, this, request)}
|
|---|
| 148 | `;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | };
|
|---|
| 152 | var _default = exports.default = loader; |
|---|