css-loader 5.2.6 → 6.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/README.md +298 -135
- package/dist/index.js +38 -28
- package/dist/options.json +82 -32
- package/dist/plugins/postcss-icss-parser.js +1 -0
- package/dist/plugins/postcss-import-parser.js +6 -0
- package/dist/plugins/postcss-url-parser.js +43 -8
- package/dist/runtime/cssWithMappingToString.js +5 -1
- package/dist/runtime/getUrl.js +6 -7
- package/dist/utils.js +270 -89
- package/package.json +24 -26
package/dist/utils.js
CHANGED
|
@@ -23,14 +23,14 @@ exports.isUrlRequestable = isUrlRequestable;
|
|
|
23
23
|
exports.sort = sort;
|
|
24
24
|
exports.combineRequests = combineRequests;
|
|
25
25
|
exports.camelCase = camelCase;
|
|
26
|
+
exports.stringifyRequest = stringifyRequest;
|
|
27
|
+
exports.isDataUrl = isDataUrl;
|
|
26
28
|
exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
|
|
27
29
|
|
|
28
30
|
var _url = require("url");
|
|
29
31
|
|
|
30
32
|
var _path = _interopRequireDefault(require("path"));
|
|
31
33
|
|
|
32
|
-
var _loaderUtils = require("loader-utils");
|
|
33
|
-
|
|
34
34
|
var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
|
|
35
35
|
|
|
36
36
|
var _postcssModulesLocalByDefault = _interopRequireDefault(require("postcss-modules-local-by-default"));
|
|
@@ -45,9 +45,78 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
45
45
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
46
46
|
Author Tobias Koppers @sokra
|
|
47
47
|
*/
|
|
48
|
-
const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
|
|
49
|
-
|
|
48
|
+
const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
|
|
50
49
|
exports.WEBPACK_IGNORE_COMMENT_REGEXP = WEBPACK_IGNORE_COMMENT_REGEXP;
|
|
50
|
+
const matchRelativePath = /^\.\.?[/\\]/;
|
|
51
|
+
|
|
52
|
+
function isAbsolutePath(str) {
|
|
53
|
+
return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isRelativePath(str) {
|
|
57
|
+
return matchRelativePath.test(str);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function stringifyRequest(loaderContext, request) {
|
|
61
|
+
const splitted = request.split("!");
|
|
62
|
+
const {
|
|
63
|
+
context
|
|
64
|
+
} = loaderContext;
|
|
65
|
+
return JSON.stringify(splitted.map(part => {
|
|
66
|
+
// First, separate singlePath from query, because the query might contain paths again
|
|
67
|
+
const splittedPart = part.match(/^(.*?)(\?.*)/);
|
|
68
|
+
const query = splittedPart ? splittedPart[2] : "";
|
|
69
|
+
let singlePath = splittedPart ? splittedPart[1] : part;
|
|
70
|
+
|
|
71
|
+
if (isAbsolutePath(singlePath) && context) {
|
|
72
|
+
singlePath = _path.default.relative(context, singlePath);
|
|
73
|
+
|
|
74
|
+
if (isAbsolutePath(singlePath)) {
|
|
75
|
+
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
|
76
|
+
// In this case, we leave the path platform-specific without replacing any separators.
|
|
77
|
+
// @see https://github.com/webpack/loader-utils/pull/14
|
|
78
|
+
return singlePath + query;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isRelativePath(singlePath) === false) {
|
|
82
|
+
// Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
|
83
|
+
singlePath = `./${singlePath}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return singlePath.replace(/\\/g, "/") + query;
|
|
88
|
+
}).join("!"));
|
|
89
|
+
} // We can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
93
|
+
const IS_MODULE_REQUEST = /^[^?]*~/;
|
|
94
|
+
|
|
95
|
+
function urlToRequest(url, root) {
|
|
96
|
+
let request;
|
|
97
|
+
|
|
98
|
+
if (IS_NATIVE_WIN32_PATH.test(url)) {
|
|
99
|
+
// absolute windows path, keep it
|
|
100
|
+
request = url;
|
|
101
|
+
} else if (typeof root !== "undefined" && /^\//.test(url)) {
|
|
102
|
+
request = root + url;
|
|
103
|
+
} else if (/^\.\.?\//.test(url)) {
|
|
104
|
+
// A relative url stays
|
|
105
|
+
request = url;
|
|
106
|
+
} else {
|
|
107
|
+
// every other url is threaded like a relative url
|
|
108
|
+
request = `./${url}`;
|
|
109
|
+
} // A `~` makes the url an module
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (IS_MODULE_REQUEST.test(request)) {
|
|
113
|
+
request = request.replace(IS_MODULE_REQUEST, "");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return request;
|
|
117
|
+
} // eslint-disable-next-line no-useless-escape
|
|
118
|
+
|
|
119
|
+
|
|
51
120
|
const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/;
|
|
52
121
|
const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
|
|
53
122
|
|
|
@@ -253,8 +322,79 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
|
|
|
253
322
|
|
|
254
323
|
const relativeResourcePath = normalizePath(_path.default.relative(options.context, loaderContext.resourcePath)); // eslint-disable-next-line no-param-reassign
|
|
255
324
|
|
|
256
|
-
options.content = `${
|
|
257
|
-
|
|
325
|
+
options.content = `${relativeMatchResource}${relativeResourcePath}\x00${localName}`;
|
|
326
|
+
let {
|
|
327
|
+
hashFunction,
|
|
328
|
+
hashDigest,
|
|
329
|
+
hashDigestLength
|
|
330
|
+
} = options;
|
|
331
|
+
const mathes = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
|
|
332
|
+
|
|
333
|
+
if (mathes) {
|
|
334
|
+
const hashName = mathes[2] || hashFunction;
|
|
335
|
+
hashFunction = mathes[1] || hashFunction;
|
|
336
|
+
hashDigest = mathes[3] || hashDigest;
|
|
337
|
+
hashDigestLength = mathes[4] || hashDigestLength; // `hash` and `contenthash` are same in `loader-utils` context
|
|
338
|
+
// let's keep `hash` for backward compatibility
|
|
339
|
+
// eslint-disable-next-line no-param-reassign
|
|
340
|
+
|
|
341
|
+
localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => hashName === "fullhash" ? "[fullhash]" : "[contenthash]");
|
|
342
|
+
} // eslint-disable-next-line no-underscore-dangle
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
|
|
346
|
+
|
|
347
|
+
const {
|
|
348
|
+
hashSalt
|
|
349
|
+
} = options;
|
|
350
|
+
|
|
351
|
+
if (hashSalt) {
|
|
352
|
+
hash.update(hashSalt);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
hash.update(options.content);
|
|
356
|
+
const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength).replace(/[/+]/g, "_").replace(/^\d/g, "_"); // TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property, also `data` for `getPath` should be looks good without chunk property
|
|
357
|
+
|
|
358
|
+
const ext = _path.default.extname(loaderContext.resourcePath);
|
|
359
|
+
|
|
360
|
+
const base = _path.default.basename(loaderContext.resourcePath);
|
|
361
|
+
|
|
362
|
+
const name = base.slice(0, base.length - ext.length);
|
|
363
|
+
const data = {
|
|
364
|
+
filename: _path.default.relative(options.context, loaderContext.resourcePath),
|
|
365
|
+
contentHash: localIdentHash,
|
|
366
|
+
chunk: {
|
|
367
|
+
name,
|
|
368
|
+
hash: localIdentHash,
|
|
369
|
+
contentHash: localIdentHash
|
|
370
|
+
}
|
|
371
|
+
}; // eslint-disable-next-line no-underscore-dangle
|
|
372
|
+
|
|
373
|
+
let result = loaderContext._compilation.getPath(localIdentName, data);
|
|
374
|
+
|
|
375
|
+
if (options.regExp) {
|
|
376
|
+
const match = loaderContext.resourcePath.match(options.regExp);
|
|
377
|
+
|
|
378
|
+
if (match) {
|
|
379
|
+
match.forEach((matched, i) => {
|
|
380
|
+
result = result.replace(new RegExp(`\\[${i}\\]`, "ig"), matched);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function fixedEncodeURIComponent(str) {
|
|
389
|
+
return str.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function isDataUrl(url) {
|
|
393
|
+
if (/^data:/i.test(url)) {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return false;
|
|
258
398
|
}
|
|
259
399
|
|
|
260
400
|
const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
|
|
@@ -277,6 +417,11 @@ function normalizeUrl(url, isStringValue) {
|
|
|
277
417
|
|
|
278
418
|
normalizedUrl = unescape(normalizedUrl);
|
|
279
419
|
|
|
420
|
+
if (isDataUrl(url)) {
|
|
421
|
+
// Todo fixedEncodeURIComponent is workaround. Webpack resolver shouldn't handle "!" in dataURL
|
|
422
|
+
return fixedEncodeURIComponent(normalizedUrl);
|
|
423
|
+
}
|
|
424
|
+
|
|
280
425
|
try {
|
|
281
426
|
normalizedUrl = decodeURI(normalizedUrl);
|
|
282
427
|
} catch (error) {// Ignore
|
|
@@ -285,12 +430,25 @@ function normalizeUrl(url, isStringValue) {
|
|
|
285
430
|
return normalizedUrl;
|
|
286
431
|
}
|
|
287
432
|
|
|
288
|
-
function requestify(url, rootContext) {
|
|
289
|
-
if (
|
|
290
|
-
|
|
433
|
+
function requestify(url, rootContext, needToResolveURL = true) {
|
|
434
|
+
if (needToResolveURL) {
|
|
435
|
+
if (/^file:/i.test(url)) {
|
|
436
|
+
return (0, _url.fileURLToPath)(url);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return url.charAt(0) === "/" ? urlToRequest(url, rootContext) : urlToRequest(url);
|
|
291
440
|
}
|
|
292
441
|
|
|
293
|
-
|
|
442
|
+
if (url.charAt(0) === "/" || /^file:/i.test(url)) {
|
|
443
|
+
return url;
|
|
444
|
+
} // A `~` makes the url an module
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
if (IS_MODULE_REQUEST.test(url)) {
|
|
448
|
+
return url.replace(IS_MODULE_REQUEST, "");
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return url;
|
|
294
452
|
}
|
|
295
453
|
|
|
296
454
|
function getFilter(filter, resourcePath) {
|
|
@@ -304,6 +462,11 @@ function getFilter(filter, resourcePath) {
|
|
|
304
462
|
}
|
|
305
463
|
|
|
306
464
|
function getValidLocalName(localName, exportLocalsConvention) {
|
|
465
|
+
if (typeof exportLocalsConvention === "function") {
|
|
466
|
+
const result = exportLocalsConvention(localName);
|
|
467
|
+
return Array.isArray(result) ? result[0] : result;
|
|
468
|
+
}
|
|
469
|
+
|
|
307
470
|
if (exportLocalsConvention === "dashesOnly") {
|
|
308
471
|
return dashesCamelCase(localName);
|
|
309
472
|
}
|
|
@@ -311,77 +474,86 @@ function getValidLocalName(localName, exportLocalsConvention) {
|
|
|
311
474
|
return camelCase(localName);
|
|
312
475
|
}
|
|
313
476
|
|
|
314
|
-
const
|
|
315
|
-
const
|
|
477
|
+
const IS_MODULES = /\.module(s)?\.\w+$/i;
|
|
478
|
+
const IS_ICSS = /\.icss\.\w+$/i;
|
|
316
479
|
|
|
317
480
|
function getModulesOptions(rawOptions, loaderContext) {
|
|
481
|
+
if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
|
|
318
485
|
const resourcePath = // eslint-disable-next-line no-underscore-dangle
|
|
319
486
|
loaderContext._module && loaderContext._module.matchResource || loaderContext.resourcePath;
|
|
320
|
-
let
|
|
487
|
+
let auto;
|
|
488
|
+
let rawModulesOptions;
|
|
321
489
|
|
|
322
490
|
if (typeof rawOptions.modules === "undefined") {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
491
|
+
rawModulesOptions = {};
|
|
492
|
+
auto = true;
|
|
493
|
+
} else if (typeof rawOptions.modules === "boolean") {
|
|
494
|
+
rawModulesOptions = {};
|
|
495
|
+
} else if (typeof rawOptions.modules === "string") {
|
|
496
|
+
rawModulesOptions = {
|
|
497
|
+
mode: rawOptions.modules
|
|
498
|
+
};
|
|
499
|
+
} else {
|
|
500
|
+
rawModulesOptions = rawOptions.modules;
|
|
501
|
+
({
|
|
502
|
+
auto
|
|
503
|
+
} = rawModulesOptions);
|
|
504
|
+
} // eslint-disable-next-line no-underscore-dangle
|
|
328
505
|
|
|
329
|
-
if (!isModules && !isIcss) {
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
} else if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
506
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
507
|
+
const {
|
|
508
|
+
outputOptions
|
|
509
|
+
} = loaderContext._compilation;
|
|
510
|
+
const modulesOptions = {
|
|
511
|
+
auto,
|
|
339
512
|
mode: "local",
|
|
340
513
|
exportGlobals: false,
|
|
341
514
|
localIdentName: "[hash:base64]",
|
|
342
515
|
localIdentContext: loaderContext.rootContext,
|
|
343
|
-
|
|
516
|
+
localIdentHashSalt: outputOptions.hashSalt,
|
|
517
|
+
localIdentHashFunction: outputOptions.hashFunction,
|
|
518
|
+
localIdentHashDigest: outputOptions.hashDigest,
|
|
519
|
+
localIdentHashDigestLength: outputOptions.hashDigestLength,
|
|
344
520
|
// eslint-disable-next-line no-undefined
|
|
345
521
|
localIdentRegExp: undefined,
|
|
346
522
|
// eslint-disable-next-line no-undefined
|
|
347
523
|
getLocalIdent: undefined,
|
|
348
524
|
namedExport: false,
|
|
349
|
-
exportLocalsConvention: "asIs",
|
|
350
|
-
exportOnlyLocals: false
|
|
525
|
+
exportLocalsConvention: rawModulesOptions.namedExport === true && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
|
|
526
|
+
exportOnlyLocals: false,
|
|
527
|
+
...rawModulesOptions
|
|
351
528
|
};
|
|
352
529
|
|
|
353
|
-
if (typeof
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (rawOptions.modules) {
|
|
357
|
-
if (typeof rawOptions.modules.auto === "boolean") {
|
|
358
|
-
const isModules = rawOptions.modules.auto && moduleRegExp.test(resourcePath);
|
|
359
|
-
|
|
360
|
-
if (!isModules) {
|
|
361
|
-
return false;
|
|
362
|
-
}
|
|
363
|
-
} else if (rawOptions.modules.auto instanceof RegExp) {
|
|
364
|
-
const isModules = rawOptions.modules.auto.test(resourcePath);
|
|
530
|
+
if (typeof modulesOptions.auto === "boolean") {
|
|
531
|
+
const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
|
|
532
|
+
let isIcss;
|
|
365
533
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
} else if (typeof rawOptions.modules.auto === "function") {
|
|
370
|
-
const isModule = rawOptions.modules.auto(resourcePath);
|
|
534
|
+
if (!isModules) {
|
|
535
|
+
isIcss = IS_ICSS.test(resourcePath);
|
|
371
536
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
537
|
+
if (isIcss) {
|
|
538
|
+
modulesOptions.mode = "icss";
|
|
375
539
|
}
|
|
540
|
+
}
|
|
376
541
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
542
|
+
if (!isModules && !isIcss) {
|
|
543
|
+
return false;
|
|
380
544
|
}
|
|
545
|
+
} else if (modulesOptions.auto instanceof RegExp) {
|
|
546
|
+
const isModules = modulesOptions.auto.test(resourcePath);
|
|
381
547
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
548
|
+
if (!isModules) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
} else if (typeof modulesOptions.auto === "function") {
|
|
552
|
+
const isModule = modulesOptions.auto(resourcePath);
|
|
553
|
+
|
|
554
|
+
if (!isModule) {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
385
557
|
}
|
|
386
558
|
|
|
387
559
|
if (typeof modulesOptions.mode === "function") {
|
|
@@ -393,15 +565,11 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
393
565
|
throw new Error('The "modules.namedExport" option requires the "esModules" option to be enabled');
|
|
394
566
|
}
|
|
395
567
|
|
|
396
|
-
if (modulesOptions.exportLocalsConvention !== "camelCaseOnly" && modulesOptions.exportLocalsConvention !== "dashesOnly") {
|
|
568
|
+
if (typeof modulesOptions.exportLocalsConvention === "string" && modulesOptions.exportLocalsConvention !== "camelCaseOnly" && modulesOptions.exportLocalsConvention !== "dashesOnly") {
|
|
397
569
|
throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
|
|
398
570
|
}
|
|
399
571
|
}
|
|
400
572
|
|
|
401
|
-
if (/\[emoji(?::(\d+))?\]/i.test(modulesOptions.localIdentName)) {
|
|
402
|
-
loaderContext.emitWarning("Emoji is deprecated and will be removed in next major release.");
|
|
403
|
-
}
|
|
404
|
-
|
|
405
573
|
return modulesOptions;
|
|
406
574
|
}
|
|
407
575
|
|
|
@@ -442,11 +610,15 @@ function shouldUseURLPlugin(options) {
|
|
|
442
610
|
}
|
|
443
611
|
|
|
444
612
|
function shouldUseModulesPlugins(options) {
|
|
445
|
-
|
|
613
|
+
if (typeof options.modules === "boolean" && options.modules === false) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return options.modules.mode !== "icss";
|
|
446
618
|
}
|
|
447
619
|
|
|
448
620
|
function shouldUseIcssPlugin(options) {
|
|
449
|
-
return
|
|
621
|
+
return Boolean(options.modules);
|
|
450
622
|
}
|
|
451
623
|
|
|
452
624
|
function getModulesPlugins(options, loaderContext) {
|
|
@@ -455,7 +627,10 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
455
627
|
getLocalIdent,
|
|
456
628
|
localIdentName,
|
|
457
629
|
localIdentContext,
|
|
458
|
-
|
|
630
|
+
localIdentHashSalt,
|
|
631
|
+
localIdentHashFunction,
|
|
632
|
+
localIdentHashDigest,
|
|
633
|
+
localIdentHashDigestLength,
|
|
459
634
|
localIdentRegExp
|
|
460
635
|
} = options.modules;
|
|
461
636
|
let plugins = [];
|
|
@@ -470,7 +645,10 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
470
645
|
if (typeof getLocalIdent !== "undefined") {
|
|
471
646
|
localIdent = getLocalIdent(loaderContext, localIdentName, unescape(exportName), {
|
|
472
647
|
context: localIdentContext,
|
|
473
|
-
|
|
648
|
+
hashSalt: localIdentHashSalt,
|
|
649
|
+
hashFunction: localIdentHashFunction,
|
|
650
|
+
hashDigest: localIdentHashDigest,
|
|
651
|
+
hashDigestLength: localIdentHashDigestLength,
|
|
474
652
|
regExp: localIdentRegExp
|
|
475
653
|
});
|
|
476
654
|
} // A null/undefined value signals that we should invoke the default
|
|
@@ -480,7 +658,10 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
480
658
|
if (typeof localIdent === "undefined" || localIdent === null) {
|
|
481
659
|
localIdent = defaultGetLocalIdent(loaderContext, localIdentName, unescape(exportName), {
|
|
482
660
|
context: localIdentContext,
|
|
483
|
-
|
|
661
|
+
hashSalt: localIdentHashSalt,
|
|
662
|
+
hashFunction: localIdentHashFunction,
|
|
663
|
+
hashDigest: localIdentHashDigest,
|
|
664
|
+
hashDigestLength: localIdentHashDigestLength,
|
|
484
665
|
regExp: localIdentRegExp
|
|
485
666
|
});
|
|
486
667
|
return escapeLocalIdent(localIdent).replace(/\\\[local\\]/gi, exportName);
|
|
@@ -498,7 +679,6 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
498
679
|
return plugins;
|
|
499
680
|
}
|
|
500
681
|
|
|
501
|
-
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
502
682
|
const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
|
|
503
683
|
|
|
504
684
|
function getURLType(source) {
|
|
@@ -582,14 +762,15 @@ function getImportCode(imports, options) {
|
|
|
582
762
|
const {
|
|
583
763
|
importName,
|
|
584
764
|
url,
|
|
585
|
-
icss
|
|
765
|
+
icss,
|
|
766
|
+
type
|
|
586
767
|
} = item;
|
|
587
768
|
|
|
588
769
|
if (options.esModule) {
|
|
589
770
|
if (icss && options.modules.namedExport) {
|
|
590
771
|
code += `import ${options.modules.exportOnlyLocals ? "" : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
|
|
591
772
|
} else {
|
|
592
|
-
code += `import ${importName} from ${url};\n`;
|
|
773
|
+
code += type === "url" ? `var ${importName} = new URL(${url}, import.meta.url);\n` : `import ${importName} from ${url};\n`;
|
|
593
774
|
}
|
|
594
775
|
} else {
|
|
595
776
|
code += `var ${importName} = require(${url});\n`;
|
|
@@ -685,15 +866,19 @@ function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
|
|
|
685
866
|
|
|
686
867
|
let localsCode = "";
|
|
687
868
|
|
|
688
|
-
const addExportToLocalsCode = (
|
|
689
|
-
|
|
690
|
-
localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
|
691
|
-
} else {
|
|
692
|
-
if (localsCode) {
|
|
693
|
-
localsCode += `,\n`;
|
|
694
|
-
}
|
|
869
|
+
const addExportToLocalsCode = (names, value) => {
|
|
870
|
+
const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
|
|
695
871
|
|
|
696
|
-
|
|
872
|
+
for (const name of normalizedNames) {
|
|
873
|
+
if (options.modules.namedExport) {
|
|
874
|
+
localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
|
875
|
+
} else {
|
|
876
|
+
if (localsCode) {
|
|
877
|
+
localsCode += `,\n`;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
|
|
881
|
+
}
|
|
697
882
|
}
|
|
698
883
|
};
|
|
699
884
|
|
|
@@ -701,16 +886,17 @@ function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
|
|
|
701
886
|
name,
|
|
702
887
|
value
|
|
703
888
|
} of exports) {
|
|
889
|
+
if (typeof options.modules.exportLocalsConvention === "function") {
|
|
890
|
+
addExportToLocalsCode(options.modules.exportLocalsConvention(name), value); // eslint-disable-next-line no-continue
|
|
891
|
+
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
|
|
704
895
|
switch (options.modules.exportLocalsConvention) {
|
|
705
896
|
case "camelCase":
|
|
706
897
|
{
|
|
707
|
-
addExportToLocalsCode(name, value);
|
|
708
898
|
const modifiedName = camelCase(name);
|
|
709
|
-
|
|
710
|
-
if (modifiedName !== name) {
|
|
711
|
-
addExportToLocalsCode(modifiedName, value);
|
|
712
|
-
}
|
|
713
|
-
|
|
899
|
+
addExportToLocalsCode([name, modifiedName], value);
|
|
714
900
|
break;
|
|
715
901
|
}
|
|
716
902
|
|
|
@@ -722,13 +908,8 @@ function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
|
|
|
722
908
|
|
|
723
909
|
case "dashes":
|
|
724
910
|
{
|
|
725
|
-
addExportToLocalsCode(name, value);
|
|
726
911
|
const modifiedName = dashesCamelCase(name);
|
|
727
|
-
|
|
728
|
-
if (modifiedName !== name) {
|
|
729
|
-
addExportToLocalsCode(modifiedName, value);
|
|
730
|
-
}
|
|
731
|
-
|
|
912
|
+
addExportToLocalsCode([name, modifiedName], value);
|
|
732
913
|
break;
|
|
733
914
|
}
|
|
734
915
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.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": ">= 12.13.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "npm run build -- -w",
|
|
@@ -39,56 +39,54 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"webpack": "^
|
|
42
|
+
"webpack": "^5.0.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"icss-utils": "^5.1.0",
|
|
46
|
-
"loader-utils": "^2.0.0",
|
|
47
46
|
"postcss": "^8.2.15",
|
|
48
47
|
"postcss-modules-extract-imports": "^3.0.0",
|
|
49
48
|
"postcss-modules-local-by-default": "^4.0.0",
|
|
50
49
|
"postcss-modules-scope": "^3.0.0",
|
|
51
50
|
"postcss-modules-values": "^4.0.0",
|
|
52
51
|
"postcss-value-parser": "^4.1.0",
|
|
53
|
-
"schema-utils": "^3.0.0",
|
|
54
52
|
"semver": "^7.3.5"
|
|
55
53
|
},
|
|
56
54
|
"devDependencies": {
|
|
57
|
-
"@babel/cli": "^7.14.
|
|
58
|
-
"@babel/core": "^7.14.
|
|
59
|
-
"@babel/preset-env": "^7.14.
|
|
55
|
+
"@babel/cli": "^7.14.5",
|
|
56
|
+
"@babel/core": "^7.14.6",
|
|
57
|
+
"@babel/preset-env": "^7.14.7",
|
|
60
58
|
"@commitlint/cli": "^12.1.4",
|
|
61
59
|
"@commitlint/config-conventional": "^12.1.4",
|
|
62
60
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
63
|
-
"babel-jest": "^
|
|
61
|
+
"babel-jest": "^27.0.6",
|
|
64
62
|
"cross-env": "^7.0.3",
|
|
65
63
|
"del": "^6.0.0",
|
|
66
|
-
"del-cli": "^
|
|
67
|
-
"es-check": "^5.2.
|
|
68
|
-
"eslint": "^7.
|
|
64
|
+
"del-cli": "^4.0.1",
|
|
65
|
+
"es-check": "^5.2.4",
|
|
66
|
+
"eslint": "^7.30.0",
|
|
69
67
|
"eslint-config-prettier": "^8.3.0",
|
|
70
|
-
"eslint-plugin-import": "^2.23.
|
|
68
|
+
"eslint-plugin-import": "^2.23.4",
|
|
71
69
|
"file-loader": "^6.2.0",
|
|
72
|
-
"husky": "^
|
|
73
|
-
"jest": "^
|
|
70
|
+
"husky": "^7.0.1",
|
|
71
|
+
"jest": "^27.0.6",
|
|
74
72
|
"less": "^4.1.1",
|
|
75
|
-
"less-loader": "^
|
|
76
|
-
"lint-staged": "^11.0.
|
|
73
|
+
"less-loader": "^10.0.1",
|
|
74
|
+
"lint-staged": "^11.0.1",
|
|
77
75
|
"memfs": "^3.2.2",
|
|
78
|
-
"mini-css-extract-plugin": "^1.
|
|
76
|
+
"mini-css-extract-plugin": "^2.1.0",
|
|
79
77
|
"npm-run-all": "^4.1.5",
|
|
80
|
-
"postcss-loader": "^
|
|
78
|
+
"postcss-loader": "^6.1.1",
|
|
81
79
|
"postcss-preset-env": "^6.7.0",
|
|
82
|
-
"prettier": "^2.3.
|
|
83
|
-
"sass": "^1.
|
|
84
|
-
"sass-loader": "^
|
|
85
|
-
"standard-version": "^9.3.
|
|
80
|
+
"prettier": "^2.3.2",
|
|
81
|
+
"sass": "^1.35.2",
|
|
82
|
+
"sass-loader": "^12.1.0",
|
|
83
|
+
"standard-version": "^9.3.1",
|
|
86
84
|
"strip-ansi": "^6.0.0",
|
|
87
|
-
"style-loader": "^
|
|
85
|
+
"style-loader": "^3.1.0",
|
|
88
86
|
"stylus": "^0.54.8",
|
|
89
|
-
"stylus-loader": "^
|
|
87
|
+
"stylus-loader": "^6.1.0",
|
|
90
88
|
"url-loader": "^4.1.1",
|
|
91
|
-
"webpack": "^5.
|
|
89
|
+
"webpack": "^5.45.1"
|
|
92
90
|
},
|
|
93
91
|
"keywords": [
|
|
94
92
|
"webpack",
|