css-loader 3.6.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.md +221 -103
- package/dist/index.js +104 -73
- package/dist/options.json +48 -25
- package/dist/plugins/postcss-icss-parser.js +73 -60
- package/dist/plugins/postcss-import-parser.js +124 -51
- package/dist/plugins/postcss-url-parser.js +202 -106
- package/dist/utils.js +264 -115
- package/package.json +23 -21
package/dist/utils.js
CHANGED
|
@@ -3,15 +3,26 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.normalizeOptions = normalizeOptions;
|
|
7
|
+
exports.shouldUseModulesPlugins = shouldUseModulesPlugins;
|
|
8
|
+
exports.shouldUseImportPlugin = shouldUseImportPlugin;
|
|
9
|
+
exports.shouldUseURLPlugin = shouldUseURLPlugin;
|
|
10
|
+
exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
|
|
6
11
|
exports.normalizeUrl = normalizeUrl;
|
|
12
|
+
exports.requestify = requestify;
|
|
7
13
|
exports.getFilter = getFilter;
|
|
14
|
+
exports.getModulesOptions = getModulesOptions;
|
|
8
15
|
exports.getModulesPlugins = getModulesPlugins;
|
|
9
16
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
10
17
|
exports.getPreRequester = getPreRequester;
|
|
11
18
|
exports.getImportCode = getImportCode;
|
|
12
19
|
exports.getModuleCode = getModuleCode;
|
|
13
20
|
exports.getExportCode = getExportCode;
|
|
14
|
-
exports.
|
|
21
|
+
exports.resolveRequests = resolveRequests;
|
|
22
|
+
exports.isUrlRequestable = isUrlRequestable;
|
|
23
|
+
exports.sort = sort;
|
|
24
|
+
|
|
25
|
+
var _url = require("url");
|
|
15
26
|
|
|
16
27
|
var _path = _interopRequireDefault(require("path"));
|
|
17
28
|
|
|
@@ -39,6 +50,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
39
50
|
*/
|
|
40
51
|
const whitespace = '[\\x20\\t\\r\\n\\f]';
|
|
41
52
|
const unescapeRegExp = new RegExp(`\\\\([\\da-f]{1,6}${whitespace}?|(${whitespace})|.)`, 'ig');
|
|
53
|
+
const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
|
|
42
54
|
|
|
43
55
|
function unescape(str) {
|
|
44
56
|
return str.replace(unescapeRegExp, (_, escaped, escapedWhitespace) => {
|
|
@@ -57,26 +69,27 @@ function unescape(str) {
|
|
|
57
69
|
} // eslint-disable-next-line no-control-regex
|
|
58
70
|
|
|
59
71
|
|
|
60
|
-
const filenameReservedRegex = /[<>:"
|
|
72
|
+
const filenameReservedRegex = /[<>:"/\\|?*]/g; // eslint-disable-next-line no-control-regex
|
|
61
73
|
|
|
62
74
|
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
|
|
63
|
-
const reRelativePath = /^\.+/;
|
|
64
|
-
|
|
65
|
-
function getLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
66
|
-
if (!options.context) {
|
|
67
|
-
// eslint-disable-next-line no-param-reassign
|
|
68
|
-
options.context = loaderContext.rootContext;
|
|
69
|
-
}
|
|
70
75
|
|
|
71
|
-
|
|
76
|
+
function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
77
|
+
const {
|
|
78
|
+
context,
|
|
79
|
+
hashPrefix
|
|
80
|
+
} = options;
|
|
81
|
+
const {
|
|
82
|
+
resourcePath
|
|
83
|
+
} = loaderContext;
|
|
84
|
+
const request = (0, _normalizePath.default)(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
|
|
72
85
|
|
|
73
|
-
options.content = `${
|
|
86
|
+
options.content = `${hashPrefix + request}\x00${unescape(localName)}`; // Using `[path]` placeholder outputs `/` we need escape their
|
|
74
87
|
// Also directories can contains invalid characters for css we need escape their too
|
|
75
88
|
|
|
76
89
|
return (0, _cssesc.default)((0, _loaderUtils.interpolateName)(loaderContext, localIdentName, options) // For `[hash]` placeholder
|
|
77
|
-
.replace(/^((-?[0-9])|--)/, '_$1').replace(filenameReservedRegex, '-').replace(reControlChars, '-').replace(
|
|
90
|
+
.replace(/^((-?[0-9])|--)/, '_$1').replace(filenameReservedRegex, '-').replace(reControlChars, '-').replace(/\./g, '-'), {
|
|
78
91
|
isIdentifier: true
|
|
79
|
-
}).replace(/\\\[local
|
|
92
|
+
}).replace(/\\\[local\\]/gi, localName);
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
function normalizeUrl(url, isStringValue) {
|
|
@@ -86,95 +99,189 @@ function normalizeUrl(url, isStringValue) {
|
|
|
86
99
|
normalizedUrl = normalizedUrl.replace(/\\[\n]/g, '');
|
|
87
100
|
}
|
|
88
101
|
|
|
89
|
-
|
|
102
|
+
if (matchNativeWin32Path.test(url)) {
|
|
103
|
+
return decodeURIComponent(normalizedUrl);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return decodeURIComponent(unescape(normalizedUrl));
|
|
90
107
|
}
|
|
91
108
|
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
109
|
+
function requestify(url, rootContext) {
|
|
110
|
+
if (/^file:/i.test(url)) {
|
|
111
|
+
return (0, _url.fileURLToPath)(url);
|
|
112
|
+
}
|
|
97
113
|
|
|
114
|
+
return url.charAt(0) === '/' ? (0, _loaderUtils.urlToRequest)(url, rootContext) : (0, _loaderUtils.urlToRequest)(url);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getFilter(filter, resourcePath) {
|
|
118
|
+
return (...args) => {
|
|
98
119
|
if (typeof filter === 'function') {
|
|
99
|
-
return filter(
|
|
120
|
+
return filter(...args, resourcePath);
|
|
100
121
|
}
|
|
101
122
|
|
|
102
123
|
return true;
|
|
103
124
|
};
|
|
104
125
|
}
|
|
105
126
|
|
|
106
|
-
|
|
107
|
-
|
|
127
|
+
const moduleRegExp = /\.module\.\w+$/i;
|
|
128
|
+
|
|
129
|
+
function getModulesOptions(rawOptions, loaderContext) {
|
|
130
|
+
const {
|
|
131
|
+
resourcePath
|
|
132
|
+
} = loaderContext;
|
|
133
|
+
|
|
134
|
+
if (typeof rawOptions.modules === 'undefined') {
|
|
135
|
+
const isModules = moduleRegExp.test(resourcePath);
|
|
136
|
+
|
|
137
|
+
if (!isModules) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
} else if (typeof rawOptions.modules === 'boolean' && rawOptions.modules === false) {
|
|
108
141
|
return false;
|
|
109
142
|
}
|
|
110
143
|
|
|
111
|
-
|
|
112
|
-
|
|
144
|
+
let modulesOptions = {
|
|
145
|
+
compileType: rawOptions.icss ? 'icss' : 'module',
|
|
146
|
+
auto: true,
|
|
147
|
+
mode: 'local',
|
|
148
|
+
exportGlobals: false,
|
|
149
|
+
localIdentName: '[hash:base64]',
|
|
150
|
+
localIdentContext: loaderContext.rootContext,
|
|
151
|
+
localIdentHashPrefix: '',
|
|
152
|
+
// eslint-disable-next-line no-undefined
|
|
153
|
+
localIdentRegExp: undefined,
|
|
154
|
+
getLocalIdent: defaultGetLocalIdent,
|
|
155
|
+
namedExport: false,
|
|
156
|
+
exportLocalsConvention: 'asIs',
|
|
157
|
+
exportOnlyLocals: false
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
if (typeof rawOptions.modules === 'boolean' || typeof rawOptions.modules === 'string') {
|
|
161
|
+
modulesOptions.mode = typeof rawOptions.modules === 'string' ? rawOptions.modules : 'local';
|
|
162
|
+
} else {
|
|
163
|
+
if (rawOptions.modules) {
|
|
164
|
+
if (typeof rawOptions.modules.auto === 'boolean') {
|
|
165
|
+
const isModules = rawOptions.modules.auto && moduleRegExp.test(resourcePath);
|
|
166
|
+
|
|
167
|
+
if (!isModules) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
} else if (rawOptions.modules.auto instanceof RegExp) {
|
|
171
|
+
const isModules = rawOptions.modules.auto.test(resourcePath);
|
|
172
|
+
|
|
173
|
+
if (!isModules) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
} else if (typeof rawOptions.modules.auto === 'function') {
|
|
177
|
+
const isModule = rawOptions.modules.auto(resourcePath);
|
|
178
|
+
|
|
179
|
+
if (!isModule) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (rawOptions.modules.namedExport === true && typeof rawOptions.modules.exportLocalsConvention === 'undefined') {
|
|
185
|
+
modulesOptions.exportLocalsConvention = 'camelCaseOnly';
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
modulesOptions = { ...modulesOptions,
|
|
190
|
+
...(rawOptions.modules || {})
|
|
191
|
+
};
|
|
113
192
|
}
|
|
114
193
|
|
|
115
|
-
if (typeof
|
|
116
|
-
|
|
194
|
+
if (typeof modulesOptions.mode === 'function') {
|
|
195
|
+
modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
|
|
117
196
|
}
|
|
118
197
|
|
|
119
|
-
if (
|
|
120
|
-
|
|
198
|
+
if (modulesOptions.namedExport === true) {
|
|
199
|
+
if (rawOptions.esModule === false) {
|
|
200
|
+
throw new Error('The "modules.namedExport" option requires the "esModules" option to be enabled');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (modulesOptions.exportLocalsConvention !== 'camelCaseOnly') {
|
|
204
|
+
throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly"');
|
|
205
|
+
}
|
|
121
206
|
}
|
|
122
207
|
|
|
123
|
-
|
|
124
|
-
|
|
208
|
+
return modulesOptions;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function normalizeOptions(rawOptions, loaderContext) {
|
|
212
|
+
if (rawOptions.icss) {
|
|
213
|
+
loaderContext.emitWarning(new Error('The "icss" option is deprecated, use "modules.compileType: "icss"" instead'));
|
|
125
214
|
}
|
|
126
215
|
|
|
127
|
-
|
|
128
|
-
|
|
216
|
+
const modulesOptions = getModulesOptions(rawOptions, loaderContext);
|
|
217
|
+
return {
|
|
218
|
+
url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
|
|
219
|
+
import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
|
|
220
|
+
modules: modulesOptions,
|
|
221
|
+
// TODO remove in the next major release
|
|
222
|
+
icss: typeof rawOptions.icss === 'undefined' ? false : rawOptions.icss,
|
|
223
|
+
sourceMap: typeof rawOptions.sourceMap === 'boolean' ? rawOptions.sourceMap : loaderContext.sourceMap,
|
|
224
|
+
importLoaders: rawOptions.importLoaders,
|
|
225
|
+
esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function shouldUseImportPlugin(options) {
|
|
230
|
+
if (options.modules.exportOnlyLocals) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (typeof options.import === 'boolean') {
|
|
235
|
+
return options.import;
|
|
129
236
|
}
|
|
130
237
|
|
|
131
238
|
return true;
|
|
132
239
|
}
|
|
133
240
|
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
exportGlobals: false,
|
|
138
|
-
localIdentName: '[hash:base64]',
|
|
139
|
-
getLocalIdent,
|
|
140
|
-
hashPrefix: '',
|
|
141
|
-
localIdentRegExp: null
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (typeof options.modules === 'boolean' || typeof options.modules === 'string') {
|
|
145
|
-
modulesOptions.mode = typeof options.modules === 'string' ? options.modules : 'local';
|
|
146
|
-
} else {
|
|
147
|
-
modulesOptions = Object.assign({}, modulesOptions, options.modules);
|
|
241
|
+
function shouldUseURLPlugin(options) {
|
|
242
|
+
if (options.modules.exportOnlyLocals) {
|
|
243
|
+
return false;
|
|
148
244
|
}
|
|
149
245
|
|
|
150
|
-
if (typeof
|
|
151
|
-
|
|
246
|
+
if (typeof options.url === 'boolean') {
|
|
247
|
+
return options.url;
|
|
152
248
|
}
|
|
153
249
|
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function shouldUseModulesPlugins(options) {
|
|
254
|
+
return options.modules.compileType === 'module';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function shouldUseIcssPlugin(options) {
|
|
258
|
+
return options.icss === true || Boolean(options.modules);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function getModulesPlugins(options, loaderContext) {
|
|
262
|
+
const {
|
|
263
|
+
mode,
|
|
264
|
+
getLocalIdent,
|
|
265
|
+
localIdentName,
|
|
266
|
+
localIdentContext,
|
|
267
|
+
localIdentHashPrefix,
|
|
268
|
+
localIdentRegExp
|
|
269
|
+
} = options.modules;
|
|
154
270
|
let plugins = [];
|
|
155
271
|
|
|
156
272
|
try {
|
|
157
273
|
plugins = [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
|
158
|
-
mode
|
|
274
|
+
mode
|
|
159
275
|
}), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
|
|
160
|
-
generateScopedName
|
|
161
|
-
|
|
162
|
-
context:
|
|
163
|
-
hashPrefix:
|
|
164
|
-
regExp:
|
|
276
|
+
generateScopedName(exportName) {
|
|
277
|
+
return getLocalIdent(loaderContext, localIdentName, exportName, {
|
|
278
|
+
context: localIdentContext,
|
|
279
|
+
hashPrefix: localIdentHashPrefix,
|
|
280
|
+
regExp: localIdentRegExp
|
|
165
281
|
});
|
|
166
|
-
|
|
167
|
-
if (!localIdent) {
|
|
168
|
-
localIdent = getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
|
|
169
|
-
context: modulesOptions.context,
|
|
170
|
-
hashPrefix: modulesOptions.hashPrefix,
|
|
171
|
-
regExp: modulesOptions.localIdentRegExp
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return localIdent;
|
|
176
282
|
},
|
|
177
|
-
|
|
283
|
+
|
|
284
|
+
exportGlobals: options.modules.exportGlobals
|
|
178
285
|
})];
|
|
179
286
|
} catch (error) {
|
|
180
287
|
loaderContext.emitError(error);
|
|
@@ -229,94 +336,92 @@ function getPreRequester({
|
|
|
229
336
|
};
|
|
230
337
|
}
|
|
231
338
|
|
|
232
|
-
function getImportCode(
|
|
339
|
+
function getImportCode(imports, options) {
|
|
233
340
|
let code = '';
|
|
234
341
|
|
|
235
|
-
if (exportType === 'full') {
|
|
236
|
-
const apiUrl = (0, _loaderUtils.stringifyRequest)(loaderContext, require.resolve('./runtime/api'));
|
|
237
|
-
code += esModule ? `import ___CSS_LOADER_API_IMPORT___ from ${apiUrl};\n` : `var ___CSS_LOADER_API_IMPORT___ = require(${apiUrl});\n`;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
342
|
for (const item of imports) {
|
|
241
343
|
const {
|
|
242
344
|
importName,
|
|
243
|
-
url
|
|
345
|
+
url,
|
|
346
|
+
icss
|
|
244
347
|
} = item;
|
|
245
|
-
code += esModule ? `import ${importName} from ${url};\n` : `var ${importName} = require(${url});\n`;
|
|
348
|
+
code += options.esModule ? icss && options.modules.namedExport ? `import ${importName}, * as ${importName}_NAMED___ from ${url};\n` : `import ${importName} from ${url};\n` : `var ${importName} = require(${url});\n`;
|
|
246
349
|
}
|
|
247
350
|
|
|
248
351
|
return code ? `// Imports\n${code}` : '';
|
|
249
352
|
}
|
|
250
353
|
|
|
251
|
-
function getModuleCode(result,
|
|
252
|
-
if (
|
|
253
|
-
return '';
|
|
354
|
+
function getModuleCode(result, api, replacements, options) {
|
|
355
|
+
if (options.modules.exportOnlyLocals === true) {
|
|
356
|
+
return 'var ___CSS_LOADER_EXPORT___ = {};\n';
|
|
254
357
|
}
|
|
255
358
|
|
|
256
359
|
const {
|
|
257
360
|
css,
|
|
258
361
|
map
|
|
259
362
|
} = result;
|
|
260
|
-
const sourceMapValue = sourceMap && map ? `,${map}` : '';
|
|
363
|
+
const sourceMapValue = options.sourceMap && map ? `,${map}` : '';
|
|
261
364
|
let code = JSON.stringify(css);
|
|
262
|
-
let beforeCode =
|
|
263
|
-
beforeCode += esModule ? `var exports = ___CSS_LOADER_API_IMPORT___(${sourceMap});\n` : `exports = ___CSS_LOADER_API_IMPORT___(${sourceMap});\n`;
|
|
365
|
+
let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap});\n`;
|
|
264
366
|
|
|
265
|
-
for (const item of
|
|
367
|
+
for (const item of api) {
|
|
266
368
|
const {
|
|
267
|
-
|
|
369
|
+
url,
|
|
268
370
|
media,
|
|
269
371
|
dedupe
|
|
270
372
|
} = item;
|
|
271
|
-
beforeCode +=
|
|
373
|
+
beforeCode += url ? `___CSS_LOADER_EXPORT___.push([module.id, ${JSON.stringify(`@import url(${url});`)}${media ? `, ${JSON.stringify(media)}` : ''}]);\n` : `___CSS_LOADER_EXPORT___.i(${item.importName}${media ? `, ${JSON.stringify(media)}` : dedupe ? ', ""' : ''}${dedupe ? ', true' : ''});\n`;
|
|
272
374
|
}
|
|
273
375
|
|
|
274
|
-
for (const item of
|
|
376
|
+
for (const item of replacements) {
|
|
275
377
|
const {
|
|
276
378
|
replacementName,
|
|
277
379
|
importName,
|
|
278
|
-
|
|
279
|
-
needQuotes
|
|
380
|
+
localName
|
|
280
381
|
} = item;
|
|
281
|
-
const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? 'needQuotes: true' : []);
|
|
282
|
-
const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(', ')} }` : '';
|
|
283
|
-
beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
|
|
284
|
-
code = code.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
|
|
285
|
-
}
|
|
286
382
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
383
|
+
if (localName) {
|
|
384
|
+
code = code.replace(new RegExp(replacementName, 'g'), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
|
|
385
|
+
} else {
|
|
386
|
+
const {
|
|
387
|
+
hash,
|
|
388
|
+
needQuotes
|
|
389
|
+
} = item;
|
|
390
|
+
const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? 'needQuotes: true' : []);
|
|
391
|
+
const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(', ')} }` : '';
|
|
392
|
+
beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
|
|
393
|
+
code = code.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
|
|
394
|
+
}
|
|
294
395
|
}
|
|
295
396
|
|
|
296
|
-
return `${beforeCode}// Module\
|
|
397
|
+
return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
|
|
297
398
|
}
|
|
298
399
|
|
|
299
400
|
function dashesCamelCase(str) {
|
|
300
401
|
return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
|
|
301
402
|
}
|
|
302
403
|
|
|
303
|
-
function getExportCode(exports,
|
|
404
|
+
function getExportCode(exports, replacements, options) {
|
|
304
405
|
let code = '';
|
|
305
406
|
let localsCode = '';
|
|
306
407
|
|
|
307
408
|
const addExportToLocalsCode = (name, value) => {
|
|
308
|
-
if (
|
|
309
|
-
localsCode +=
|
|
310
|
-
}
|
|
409
|
+
if (options.modules.namedExport) {
|
|
410
|
+
localsCode += `export const ${(0, _camelcase.default)(name)} = ${JSON.stringify(value)};\n`;
|
|
411
|
+
} else {
|
|
412
|
+
if (localsCode) {
|
|
413
|
+
localsCode += `,\n`;
|
|
414
|
+
}
|
|
311
415
|
|
|
312
|
-
|
|
416
|
+
localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
|
|
417
|
+
}
|
|
313
418
|
};
|
|
314
419
|
|
|
315
420
|
for (const {
|
|
316
421
|
name,
|
|
317
422
|
value
|
|
318
423
|
} of exports) {
|
|
319
|
-
switch (
|
|
424
|
+
switch (options.modules.exportLocalsConvention) {
|
|
320
425
|
case 'camelCase':
|
|
321
426
|
{
|
|
322
427
|
addExportToLocalsCode(name, value);
|
|
@@ -360,24 +465,68 @@ function getExportCode(exports, exportType, localsConvention, icssReplacements,
|
|
|
360
465
|
}
|
|
361
466
|
}
|
|
362
467
|
|
|
363
|
-
for (const
|
|
468
|
+
for (const item of replacements) {
|
|
364
469
|
const {
|
|
365
470
|
replacementName,
|
|
366
|
-
importName,
|
|
367
471
|
localName
|
|
368
|
-
} =
|
|
369
|
-
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => exportType === 'locals' ? `" + ${importName}[${JSON.stringify(localName)}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
|
|
370
|
-
}
|
|
472
|
+
} = item;
|
|
371
473
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
474
|
+
if (localName) {
|
|
475
|
+
const {
|
|
476
|
+
importName
|
|
477
|
+
} = item;
|
|
478
|
+
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
|
|
479
|
+
} else {
|
|
480
|
+
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
|
|
377
481
|
}
|
|
482
|
+
}
|
|
378
483
|
|
|
379
|
-
|
|
484
|
+
if (localsCode) {
|
|
485
|
+
code += options.modules.namedExport ? `${localsCode}` : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
|
|
380
486
|
}
|
|
381
487
|
|
|
488
|
+
code += `${options.esModule ? 'export default' : 'module.exports ='} ___CSS_LOADER_EXPORT___;\n`;
|
|
382
489
|
return `// Exports\n${code}`;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
async function resolveRequests(resolve, context, possibleRequests) {
|
|
493
|
+
return resolve(context, possibleRequests[0]).then(result => {
|
|
494
|
+
return result;
|
|
495
|
+
}).catch(error => {
|
|
496
|
+
const [, ...tailPossibleRequests] = possibleRequests;
|
|
497
|
+
|
|
498
|
+
if (tailPossibleRequests.length === 0) {
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return resolveRequests(resolve, context, tailPossibleRequests);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function isUrlRequestable(url) {
|
|
507
|
+
// Protocol-relative URLs
|
|
508
|
+
if (/^\/\//.test(url)) {
|
|
509
|
+
return false;
|
|
510
|
+
} // `file:` protocol
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
if (/^file:/i.test(url)) {
|
|
514
|
+
return true;
|
|
515
|
+
} // Absolute URLs
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !matchNativeWin32Path.test(url)) {
|
|
519
|
+
return false;
|
|
520
|
+
} // `#` URLs
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
if (/^#/.test(url)) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function sort(a, b) {
|
|
531
|
+
return a.index - b.index;
|
|
383
532
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "css loader module for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/css-loader",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"main": "dist/cjs.js",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
16
|
+
"node": ">= 10.13.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "npm run build -- -w",
|
|
@@ -40,54 +40,56 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"webpack": "^4.
|
|
43
|
+
"webpack": "^4.27.0 || ^5.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"camelcase": "^
|
|
46
|
+
"camelcase": "^6.0.0",
|
|
47
47
|
"cssesc": "^3.0.0",
|
|
48
48
|
"icss-utils": "^4.1.1",
|
|
49
|
-
"loader-utils": "^
|
|
49
|
+
"loader-utils": "^2.0.0",
|
|
50
50
|
"normalize-path": "^3.0.0",
|
|
51
51
|
"postcss": "^7.0.32",
|
|
52
52
|
"postcss-modules-extract-imports": "^2.0.0",
|
|
53
|
-
"postcss-modules-local-by-default": "^3.0.
|
|
53
|
+
"postcss-modules-local-by-default": "^3.0.3",
|
|
54
54
|
"postcss-modules-scope": "^2.2.0",
|
|
55
55
|
"postcss-modules-values": "^3.0.0",
|
|
56
56
|
"postcss-value-parser": "^4.1.0",
|
|
57
57
|
"schema-utils": "^2.7.0",
|
|
58
|
-
"semver": "^
|
|
58
|
+
"semver": "^7.3.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@babel/cli": "^7.10.
|
|
62
|
-
"@babel/core": "^7.10.
|
|
63
|
-
"@babel/preset-env": "^7.10.
|
|
64
|
-
"@commitlint/cli": "^
|
|
65
|
-
"@commitlint/config-conventional": "^
|
|
61
|
+
"@babel/cli": "^7.10.5",
|
|
62
|
+
"@babel/core": "^7.10.5",
|
|
63
|
+
"@babel/preset-env": "^7.10.4",
|
|
64
|
+
"@commitlint/cli": "^9.1.2",
|
|
65
|
+
"@commitlint/config-conventional": "^9.1.1",
|
|
66
66
|
"@webpack-contrib/defaults": "^6.3.0",
|
|
67
67
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
68
|
-
"babel-jest": "^
|
|
68
|
+
"babel-jest": "^26.1.0",
|
|
69
69
|
"cross-env": "^7.0.2",
|
|
70
70
|
"del": "^5.1.0",
|
|
71
71
|
"del-cli": "^3.0.1",
|
|
72
72
|
"es-check": "^5.1.0",
|
|
73
|
-
"eslint": "^
|
|
73
|
+
"eslint": "^7.5.0",
|
|
74
74
|
"eslint-config-prettier": "^6.11.0",
|
|
75
|
-
"eslint-plugin-import": "^2.
|
|
75
|
+
"eslint-plugin-import": "^2.22.0",
|
|
76
76
|
"file-loader": "^6.0.0",
|
|
77
77
|
"husky": "^4.2.5",
|
|
78
|
-
"jest": "^
|
|
79
|
-
"lint-staged": "^10.2.
|
|
78
|
+
"jest": "^26.1.0",
|
|
79
|
+
"lint-staged": "^10.2.11",
|
|
80
80
|
"memfs": "^3.2.0",
|
|
81
|
+
"mini-css-extract-plugin": "^0.9.0",
|
|
81
82
|
"npm-run-all": "^4.1.5",
|
|
82
83
|
"postcss-loader": "^3.0.0",
|
|
83
84
|
"postcss-preset-env": "^6.7.0",
|
|
84
85
|
"prettier": "^2.0.5",
|
|
85
|
-
"sass": "^1.26.
|
|
86
|
-
"sass-loader": "^
|
|
87
|
-
"standard-version": "^8.0.
|
|
86
|
+
"sass": "^1.26.10",
|
|
87
|
+
"sass-loader": "^9.0.2",
|
|
88
|
+
"standard-version": "^8.0.2",
|
|
88
89
|
"strip-ansi": "^6.0.0",
|
|
90
|
+
"style-loader": "^1.2.1",
|
|
89
91
|
"url-loader": "^4.1.0",
|
|
90
|
-
"webpack": "^4.
|
|
92
|
+
"webpack": "^4.44.0"
|
|
91
93
|
},
|
|
92
94
|
"keywords": [
|
|
93
95
|
"webpack",
|