UNPKG

9.01 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getExportLazyStyleCode = getExportLazyStyleCode;
7exports.getExportStyleCode = getExportStyleCode;
8exports.getImportInsertBySelectorCode = getImportInsertBySelectorCode;
9exports.getImportInsertStyleElementCode = getImportInsertStyleElementCode;
10exports.getImportIsOldIECode = getImportIsOldIECode;
11exports.getImportLinkAPICode = getImportLinkAPICode;
12exports.getImportLinkContentCode = getImportLinkContentCode;
13exports.getImportStyleAPICode = getImportStyleAPICode;
14exports.getImportStyleContentCode = getImportStyleContentCode;
15exports.getImportStyleDomAPICode = getImportStyleDomAPICode;
16exports.getInsertOptionCode = getInsertOptionCode;
17exports.getLinkHmrCode = getLinkHmrCode;
18exports.getSetAttributesCode = getSetAttributesCode;
19exports.getStyleHmrCode = getStyleHmrCode;
20exports.getStyleTagTransformFn = getStyleTagTransformFn;
21exports.getStyleTagTransformFnCode = getStyleTagTransformFnCode;
22exports.getdomAPI = getdomAPI;
23exports.stringifyRequest = stringifyRequest;
24var _path = _interopRequireDefault(require("path"));
25var _isEqualLocals = _interopRequireDefault(require("./runtime/isEqualLocals"));
26function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27function stringifyRequest(loaderContext, request) {
28 return JSON.stringify(loaderContext.utils.contextify(loaderContext.context, request));
29}
30function getImportLinkAPICode(esModule, loaderContext) {
31 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/injectStylesIntoLinkTag.js")}`);
32 return esModule ? `import API from ${modulePath};` : `var API = require(${modulePath});`;
33}
34function getImportLinkContentCode(esModule, loaderContext, request) {
35 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
36 return esModule ? `import content from ${modulePath};` : `var content = require(${modulePath});`;
37}
38function getImportStyleAPICode(esModule, loaderContext) {
39 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/injectStylesIntoStyleTag.js")}`);
40 return esModule ? `import API from ${modulePath};` : `var API = require(${modulePath});`;
41}
42function getImportStyleDomAPICode(esModule, loaderContext, isSingleton, isAuto) {
43 const styleAPI = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/styleDomAPI.js")}`);
44 const singletonAPI = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/singletonStyleDomAPI.js")}`);
45 if (isAuto) {
46 return esModule ? `import domAPI from ${styleAPI};
47 import domAPISingleton from ${singletonAPI};` : `var domAPI = require(${styleAPI});
48 var domAPISingleton = require(${singletonAPI});`;
49 }
50 return esModule ? `import domAPI from ${isSingleton ? singletonAPI : styleAPI};` : `var domAPI = require(${isSingleton ? singletonAPI : styleAPI});`;
51}
52function getImportStyleContentCode(esModule, loaderContext, request) {
53 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
54 return esModule ? `import content, * as namedExport from ${modulePath};` : `var content = require(${modulePath});`;
55}
56function getImportInsertBySelectorCode(esModule, loaderContext, insertType, options) {
57 if (insertType === "module-path") {
58 const modulePath = stringifyRequest(loaderContext, `${options.insert}`);
59 loaderContext.addBuildDependency(options.insert);
60 return esModule ? `import insertFn from ${modulePath};` : `var insertFn = require(${modulePath});`;
61 }
62 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/insertBySelector.js")}`);
63 return esModule ? `import insertFn from ${modulePath};` : `var insertFn = require(${modulePath});`;
64}
65function getInsertOptionCode(insertType, options) {
66 if (insertType === "module-path") {
67 return `options.insert = insertFn;`;
68 }
69 const insert = options.insert ? JSON.stringify(options.insert) : '"head"';
70 return `options.insert = insertFn.bind(null, ${insert});`;
71}
72function getImportInsertStyleElementCode(esModule, loaderContext) {
73 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/insertStyleElement.js")}`);
74 return esModule ? `import insertStyleElement from ${modulePath};` : `var insertStyleElement = require(${modulePath});`;
75}
76function getStyleHmrCode(esModule, loaderContext, request, lazy) {
77 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
78 return `
79if (module.hot) {
80 if (!content.locals || module.hot.invalidate) {
81 var isEqualLocals = ${_isEqualLocals.default.toString()};
82 var isNamedExport = ${esModule ? "!content.locals" : false};
83 var oldLocals = isNamedExport ? namedExport : content.locals;
84
85 module.hot.accept(
86 ${modulePath},
87 function () {
88 ${esModule ? `if (!isEqualLocals(oldLocals, isNamedExport ? namedExport : content.locals, isNamedExport)) {
89 module.hot.invalidate();
90
91 return;
92 }
93
94 oldLocals = isNamedExport ? namedExport : content.locals;
95
96 ${lazy ? `if (update && refs > 0) {
97 update(content);
98 }` : `update(content);`}` : `content = require(${modulePath});
99
100 content = content.__esModule ? content.default : content;
101
102 ${lazy ? "" : `if (typeof content === 'string') {
103 content = [[module.id, content, '']];
104 }`}
105
106 if (!isEqualLocals(oldLocals, content.locals)) {
107 module.hot.invalidate();
108
109 return;
110 }
111
112 oldLocals = content.locals;
113
114 ${lazy ? `if (update && refs > 0) {
115 update(content);
116 }` : `update(content);`}`}
117 }
118 )
119 }
120
121 module.hot.dispose(function() {
122 ${lazy ? `if (update) {
123 update();
124 }` : `update();`}
125 });
126}
127`;
128}
129function getLinkHmrCode(esModule, loaderContext, request) {
130 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
131 return `
132if (module.hot) {
133 module.hot.accept(
134 ${modulePath},
135 function() {
136 ${esModule ? "update(content);" : `content = require(${modulePath});
137
138 content = content.__esModule ? content.default : content;
139
140 update(content);`}
141 }
142 );
143
144 module.hot.dispose(function() {
145 update();
146 });
147}`;
148}
149function getdomAPI(isAuto) {
150 return isAuto ? "isOldIE() ? domAPISingleton : domAPI" : "domAPI";
151}
152function getImportIsOldIECode(esModule, loaderContext) {
153 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/isOldIE.js")}`);
154 return esModule ? `import isOldIE from ${modulePath};` : `var isOldIE = require(${modulePath});`;
155}
156function getStyleTagTransformFnCode(esModule, loaderContext, options, isSingleton) {
157 if (isSingleton) {
158 return "";
159 }
160 if (typeof options.styleTagTransform !== "undefined") {
161 const modulePath = stringifyRequest(loaderContext, `${options.styleTagTransform}`);
162 loaderContext.addBuildDependency(options.styleTagTransform);
163 return esModule ? `import styleTagTransformFn from ${modulePath};` : `var styleTagTransformFn = require(${modulePath});`;
164 }
165 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/styleTagTransform.js")}`);
166 return esModule ? `import styleTagTransformFn from ${modulePath};` : `var styleTagTransformFn = require(${modulePath});`;
167}
168function getStyleTagTransformFn(options, isSingleton) {
169 return isSingleton ? "" : `options.styleTagTransform = styleTagTransformFn`;
170}
171function getExportStyleCode(esModule, loaderContext, request) {
172 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
173 return esModule ? `export * from ${modulePath};
174 export default content && content.locals ? content.locals : undefined;` : "module.exports = content && content.locals || {};";
175}
176function getExportLazyStyleCode(esModule, loaderContext, request) {
177 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
178 return esModule ? `export * from ${modulePath};
179 export default exported;` : "module.exports = exported;";
180}
181function getSetAttributesCode(esModule, loaderContext, options) {
182 let modulePath;
183 if (typeof options.attributes !== "undefined") {
184 modulePath = options.attributes.nonce !== "undefined" ? stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/setAttributesWithAttributesAndNonce.js")}`) : stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/setAttributesWithAttributes.js")}`);
185 } else {
186 modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/setAttributesWithoutAttributes.js")}`);
187 }
188 return esModule ? `import setAttributes from ${modulePath};` : `var setAttributes = require(${modulePath});`;
189}
190
191// eslint-disable-next-line import/prefer-default-export
\No newline at end of file