css-loader 6.0.0 → 6.4.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 +302 -72
- package/dist/index.js +19 -27
- package/dist/options.json +58 -26
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/postcss-icss-parser.js +14 -7
- package/dist/plugins/postcss-import-parser.js +70 -12
- package/dist/runtime/api.js +53 -17
- package/dist/runtime/getUrl.js +1 -5
- package/dist/runtime/noSourceMaps.js +5 -0
- package/dist/runtime/sourceMaps.js +22 -0
- package/dist/utils.js +246 -140
- package/package.json +7 -7
- package/dist/runtime/cssWithMappingToString.js +0 -36
package/dist/utils.js
CHANGED
|
@@ -3,29 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
|
|
11
|
-
exports.normalizeUrl = normalizeUrl;
|
|
12
|
-
exports.requestify = requestify;
|
|
6
|
+
exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
|
|
7
|
+
exports.camelCase = camelCase;
|
|
8
|
+
exports.combineRequests = combineRequests;
|
|
9
|
+
exports.getExportCode = getExportCode;
|
|
13
10
|
exports.getFilter = getFilter;
|
|
11
|
+
exports.getImportCode = getImportCode;
|
|
12
|
+
exports.getModuleCode = getModuleCode;
|
|
14
13
|
exports.getModulesOptions = getModulesOptions;
|
|
15
14
|
exports.getModulesPlugins = getModulesPlugins;
|
|
16
|
-
exports.normalizeSourceMap = normalizeSourceMap;
|
|
17
15
|
exports.getPreRequester = getPreRequester;
|
|
18
|
-
exports.
|
|
19
|
-
exports.getModuleCode = getModuleCode;
|
|
20
|
-
exports.getExportCode = getExportCode;
|
|
21
|
-
exports.resolveRequests = resolveRequests;
|
|
16
|
+
exports.isDataUrl = isDataUrl;
|
|
22
17
|
exports.isUrlRequestable = isUrlRequestable;
|
|
18
|
+
exports.normalizeOptions = normalizeOptions;
|
|
19
|
+
exports.normalizeSourceMap = normalizeSourceMap;
|
|
20
|
+
exports.normalizeUrl = normalizeUrl;
|
|
21
|
+
exports.requestify = requestify;
|
|
22
|
+
exports.resolveRequests = resolveRequests;
|
|
23
|
+
exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
|
|
24
|
+
exports.shouldUseImportPlugin = shouldUseImportPlugin;
|
|
25
|
+
exports.shouldUseModulesPlugins = shouldUseModulesPlugins;
|
|
26
|
+
exports.shouldUseURLPlugin = shouldUseURLPlugin;
|
|
23
27
|
exports.sort = sort;
|
|
24
|
-
exports.combineRequests = combineRequests;
|
|
25
|
-
exports.camelCase = camelCase;
|
|
26
28
|
exports.stringifyRequest = stringifyRequest;
|
|
27
|
-
exports.isDataUrl = isDataUrl;
|
|
28
|
-
exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
|
|
29
29
|
|
|
30
30
|
var _url = require("url");
|
|
31
31
|
|
|
@@ -313,55 +313,62 @@ function escapeLocalIdent(localident) {
|
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const relativeResourcePath = normalizePath(_path.default.relative(
|
|
316
|
+
const {
|
|
317
|
+
context,
|
|
318
|
+
hashSalt
|
|
319
|
+
} = options;
|
|
320
|
+
const {
|
|
321
|
+
resourcePath
|
|
322
|
+
} = loaderContext;
|
|
323
|
+
const relativeResourcePath = normalizePath(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
|
|
324
324
|
|
|
325
|
-
options.content = `${
|
|
325
|
+
options.content = `${relativeResourcePath}\x00${localName}`;
|
|
326
326
|
let {
|
|
327
327
|
hashFunction,
|
|
328
328
|
hashDigest,
|
|
329
329
|
hashDigestLength
|
|
330
330
|
} = options;
|
|
331
|
-
const
|
|
331
|
+
const matches = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
|
|
332
332
|
|
|
333
|
-
if (
|
|
334
|
-
const hashName =
|
|
335
|
-
hashFunction =
|
|
336
|
-
hashDigest =
|
|
337
|
-
hashDigestLength =
|
|
333
|
+
if (matches) {
|
|
334
|
+
const hashName = matches[2] || hashFunction;
|
|
335
|
+
hashFunction = matches[1] || hashFunction;
|
|
336
|
+
hashDigest = matches[3] || hashDigest;
|
|
337
|
+
hashDigestLength = matches[4] || hashDigestLength; // `hash` and `contenthash` are same in `loader-utils` context
|
|
338
338
|
// let's keep `hash` for backward compatibility
|
|
339
339
|
// eslint-disable-next-line no-param-reassign
|
|
340
340
|
|
|
341
341
|
localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => hashName === "fullhash" ? "[fullhash]" : "[contenthash]");
|
|
342
|
-
}
|
|
342
|
+
}
|
|
343
343
|
|
|
344
|
+
let localIdentHash = "";
|
|
344
345
|
|
|
345
|
-
|
|
346
|
+
for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
|
|
347
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
348
|
+
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
|
|
346
349
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
+
if (hashSalt) {
|
|
351
|
+
hash.update(hashSalt);
|
|
352
|
+
}
|
|
350
353
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
const tierSalt = Buffer.allocUnsafe(4);
|
|
355
|
+
tierSalt.writeUInt32LE(tier);
|
|
356
|
+
hash.update(tierSalt);
|
|
357
|
+
hash.update(options.content);
|
|
358
|
+
localIdentHash = (localIdentHash + hash.digest(hashDigest) // Remove all leading digits
|
|
359
|
+
).replace(/^\d+/, "") // Replace all slashes with underscores (same as in base64url)
|
|
360
|
+
.replace(/\//g, "_") // Remove everything that is not an alphanumeric or underscore
|
|
361
|
+
.replace(/[^A-Za-z0-9_]+/g, "").slice(0, hashDigestLength);
|
|
362
|
+
} // 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
|
|
354
363
|
|
|
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
364
|
|
|
358
|
-
const ext = _path.default.extname(
|
|
365
|
+
const ext = _path.default.extname(resourcePath);
|
|
359
366
|
|
|
360
|
-
const base = _path.default.basename(
|
|
367
|
+
const base = _path.default.basename(resourcePath);
|
|
361
368
|
|
|
362
369
|
const name = base.slice(0, base.length - ext.length);
|
|
363
370
|
const data = {
|
|
364
|
-
filename: _path.default.relative(
|
|
371
|
+
filename: _path.default.relative(context, resourcePath),
|
|
365
372
|
contentHash: localIdentHash,
|
|
366
373
|
chunk: {
|
|
367
374
|
name,
|
|
@@ -370,7 +377,33 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
|
|
|
370
377
|
}
|
|
371
378
|
}; // eslint-disable-next-line no-underscore-dangle
|
|
372
379
|
|
|
373
|
-
|
|
380
|
+
let result = loaderContext._compilation.getPath(localIdentName, data);
|
|
381
|
+
|
|
382
|
+
if (/\[folder\]/gi.test(result)) {
|
|
383
|
+
const dirname = _path.default.dirname(resourcePath);
|
|
384
|
+
|
|
385
|
+
let directory = normalizePath(_path.default.relative(context, `${dirname + _path.default.sep}_`));
|
|
386
|
+
directory = directory.substr(0, directory.length - 1);
|
|
387
|
+
let folder = "";
|
|
388
|
+
|
|
389
|
+
if (directory.length > 1) {
|
|
390
|
+
folder = _path.default.basename(directory);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
result = result.replace(/\[folder\]/gi, () => folder);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (options.regExp) {
|
|
397
|
+
const match = resourcePath.match(options.regExp);
|
|
398
|
+
|
|
399
|
+
if (match) {
|
|
400
|
+
match.forEach((matched, i) => {
|
|
401
|
+
result = result.replace(new RegExp(`\\[${i}\\]`, "ig"), matched);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return result;
|
|
374
407
|
}
|
|
375
408
|
|
|
376
409
|
function fixedEncodeURIComponent(str) {
|
|
@@ -450,17 +483,14 @@ function getFilter(filter, resourcePath) {
|
|
|
450
483
|
}
|
|
451
484
|
|
|
452
485
|
function getValidLocalName(localName, exportLocalsConvention) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return camelCase(localName);
|
|
486
|
+
const result = exportLocalsConvention(localName);
|
|
487
|
+
return Array.isArray(result) ? result[0] : result;
|
|
458
488
|
}
|
|
459
489
|
|
|
460
490
|
const IS_MODULES = /\.module(s)?\.\w+$/i;
|
|
461
491
|
const IS_ICSS = /\.icss\.\w+$/i;
|
|
462
492
|
|
|
463
|
-
function getModulesOptions(rawOptions, loaderContext) {
|
|
493
|
+
function getModulesOptions(rawOptions, exportType, loaderContext) {
|
|
464
494
|
if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
|
|
465
495
|
return false;
|
|
466
496
|
}
|
|
@@ -490,6 +520,7 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
490
520
|
const {
|
|
491
521
|
outputOptions
|
|
492
522
|
} = loaderContext._compilation;
|
|
523
|
+
const needNamedExport = exportType === "css-style-sheet" || exportType === "string";
|
|
493
524
|
const modulesOptions = {
|
|
494
525
|
auto,
|
|
495
526
|
mode: "local",
|
|
@@ -504,11 +535,44 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
504
535
|
localIdentRegExp: undefined,
|
|
505
536
|
// eslint-disable-next-line no-undefined
|
|
506
537
|
getLocalIdent: undefined,
|
|
507
|
-
namedExport: false,
|
|
508
|
-
exportLocalsConvention: rawModulesOptions.namedExport === true && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
|
|
538
|
+
namedExport: needNamedExport || false,
|
|
539
|
+
exportLocalsConvention: (rawModulesOptions.namedExport === true || needNamedExport) && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
|
|
509
540
|
exportOnlyLocals: false,
|
|
510
541
|
...rawModulesOptions
|
|
511
542
|
};
|
|
543
|
+
let exportLocalsConventionType;
|
|
544
|
+
|
|
545
|
+
if (typeof modulesOptions.exportLocalsConvention === "string") {
|
|
546
|
+
exportLocalsConventionType = modulesOptions.exportLocalsConvention;
|
|
547
|
+
|
|
548
|
+
modulesOptions.exportLocalsConvention = name => {
|
|
549
|
+
switch (exportLocalsConventionType) {
|
|
550
|
+
case "camelCase":
|
|
551
|
+
{
|
|
552
|
+
return [name, camelCase(name)];
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
case "camelCaseOnly":
|
|
556
|
+
{
|
|
557
|
+
return camelCase(name);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
case "dashes":
|
|
561
|
+
{
|
|
562
|
+
return [name, dashesCamelCase(name)];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
case "dashesOnly":
|
|
566
|
+
{
|
|
567
|
+
return dashesCamelCase(name);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
case "asIs":
|
|
571
|
+
default:
|
|
572
|
+
return name;
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
}
|
|
512
576
|
|
|
513
577
|
if (typeof modulesOptions.auto === "boolean") {
|
|
514
578
|
const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
|
|
@@ -543,12 +607,22 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
543
607
|
modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
|
|
544
608
|
}
|
|
545
609
|
|
|
610
|
+
if (needNamedExport) {
|
|
611
|
+
if (rawOptions.esModule === false) {
|
|
612
|
+
throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'esModules' option to be enabled");
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (modulesOptions.namedExport === false) {
|
|
616
|
+
throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'modules.namedExport' option to be enabled");
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
546
620
|
if (modulesOptions.namedExport === true) {
|
|
547
621
|
if (rawOptions.esModule === false) {
|
|
548
|
-
throw new Error(
|
|
622
|
+
throw new Error("The 'modules.namedExport' option requires the 'esModules' option to be enabled");
|
|
549
623
|
}
|
|
550
624
|
|
|
551
|
-
if (
|
|
625
|
+
if (typeof exportLocalsConventionType === "string" && exportLocalsConventionType !== "camelCaseOnly" && exportLocalsConventionType !== "dashesOnly") {
|
|
552
626
|
throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
|
|
553
627
|
}
|
|
554
628
|
}
|
|
@@ -557,14 +631,16 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
557
631
|
}
|
|
558
632
|
|
|
559
633
|
function normalizeOptions(rawOptions, loaderContext) {
|
|
560
|
-
const
|
|
634
|
+
const exportType = typeof rawOptions.exportType === "undefined" ? "array" : rawOptions.exportType;
|
|
635
|
+
const modulesOptions = getModulesOptions(rawOptions, exportType, loaderContext);
|
|
561
636
|
return {
|
|
562
637
|
url: typeof rawOptions.url === "undefined" ? true : rawOptions.url,
|
|
563
638
|
import: typeof rawOptions.import === "undefined" ? true : rawOptions.import,
|
|
564
639
|
modules: modulesOptions,
|
|
565
640
|
sourceMap: typeof rawOptions.sourceMap === "boolean" ? rawOptions.sourceMap : loaderContext.sourceMap,
|
|
566
641
|
importLoaders: typeof rawOptions.importLoaders === "string" ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
|
|
567
|
-
esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule
|
|
642
|
+
esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule,
|
|
643
|
+
exportType
|
|
568
644
|
};
|
|
569
645
|
}
|
|
570
646
|
|
|
@@ -793,6 +869,34 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
|
|
|
793
869
|
return JSON.stringify(resultMap);
|
|
794
870
|
}
|
|
795
871
|
|
|
872
|
+
function printParams(media, dedupe, supports, layer) {
|
|
873
|
+
let result = "";
|
|
874
|
+
|
|
875
|
+
if (typeof layer !== "undefined") {
|
|
876
|
+
result = `, ${JSON.stringify(layer)}`;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
if (typeof supports !== "undefined") {
|
|
880
|
+
result = `, ${JSON.stringify(supports)}${result}`;
|
|
881
|
+
} else if (result.length > 0) {
|
|
882
|
+
result = `, undefined${result}`;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
if (dedupe) {
|
|
886
|
+
result = `, true${result}`;
|
|
887
|
+
} else if (result.length > 0) {
|
|
888
|
+
result = `, false${result}`;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
if (media) {
|
|
892
|
+
result = `${JSON.stringify(media)}${result}`;
|
|
893
|
+
} else if (result.length > 0) {
|
|
894
|
+
result = `""${result}`;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
return result;
|
|
898
|
+
}
|
|
899
|
+
|
|
796
900
|
function getModuleCode(result, api, replacements, options, loaderContext) {
|
|
797
901
|
if (options.modules.exportOnlyLocals === true) {
|
|
798
902
|
return "";
|
|
@@ -800,15 +904,25 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
|
|
|
800
904
|
|
|
801
905
|
const sourceMapValue = options.sourceMap ? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}` : "";
|
|
802
906
|
let code = JSON.stringify(result.css);
|
|
803
|
-
let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "
|
|
907
|
+
let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___"});\n`;
|
|
804
908
|
|
|
805
909
|
for (const item of api) {
|
|
806
910
|
const {
|
|
807
911
|
url,
|
|
912
|
+
layer,
|
|
913
|
+
supports,
|
|
808
914
|
media,
|
|
809
915
|
dedupe
|
|
810
916
|
} = item;
|
|
811
|
-
|
|
917
|
+
|
|
918
|
+
if (url) {
|
|
919
|
+
// eslint-disable-next-line no-undefined
|
|
920
|
+
const printedParam = printParams(media, undefined, supports, layer);
|
|
921
|
+
beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, ${JSON.stringify(`@import url(${url});`)}${printedParam.length > 0 ? `, ${printedParam}` : ""}]);\n`;
|
|
922
|
+
} else {
|
|
923
|
+
const printedParam = printParams(media, dedupe, supports, layer);
|
|
924
|
+
beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${printedParam.length > 0 ? `, ${printedParam}` : ""});\n`;
|
|
925
|
+
}
|
|
812
926
|
}
|
|
813
927
|
|
|
814
928
|
for (const item of replacements) {
|
|
@@ -830,7 +944,14 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
|
|
|
830
944
|
beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
|
|
831
945
|
code = code.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
|
|
832
946
|
}
|
|
833
|
-
}
|
|
947
|
+
} // Indexes description:
|
|
948
|
+
// 0 - module id
|
|
949
|
+
// 1 - CSS code
|
|
950
|
+
// 2 - media
|
|
951
|
+
// 3 - source map
|
|
952
|
+
// 4 - supports
|
|
953
|
+
// 5 - layer
|
|
954
|
+
|
|
834
955
|
|
|
835
956
|
return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
|
|
836
957
|
}
|
|
@@ -839,107 +960,92 @@ function dashesCamelCase(str) {
|
|
|
839
960
|
return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
|
|
840
961
|
}
|
|
841
962
|
|
|
842
|
-
function getExportCode(exports, replacements,
|
|
963
|
+
function getExportCode(exports, replacements, icssPluginUsed, options) {
|
|
843
964
|
let code = "// Exports\n";
|
|
844
965
|
|
|
845
|
-
if (
|
|
846
|
-
|
|
847
|
-
return code;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
let localsCode = "";
|
|
851
|
-
|
|
852
|
-
const addExportToLocalsCode = (name, value) => {
|
|
853
|
-
if (options.modules.namedExport) {
|
|
854
|
-
localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
|
855
|
-
} else {
|
|
856
|
-
if (localsCode) {
|
|
857
|
-
localsCode += `,\n`;
|
|
858
|
-
}
|
|
966
|
+
if (icssPluginUsed) {
|
|
967
|
+
let localsCode = "";
|
|
859
968
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
};
|
|
969
|
+
const addExportToLocalsCode = (names, value) => {
|
|
970
|
+
const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
|
|
863
971
|
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
{
|
|
871
|
-
addExportToLocalsCode(name, value);
|
|
872
|
-
const modifiedName = camelCase(name);
|
|
873
|
-
|
|
874
|
-
if (modifiedName !== name) {
|
|
875
|
-
addExportToLocalsCode(modifiedName, value);
|
|
972
|
+
for (const name of normalizedNames) {
|
|
973
|
+
if (options.modules.namedExport) {
|
|
974
|
+
localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
|
975
|
+
} else {
|
|
976
|
+
if (localsCode) {
|
|
977
|
+
localsCode += `,\n`;
|
|
876
978
|
}
|
|
877
979
|
|
|
878
|
-
|
|
980
|
+
localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
|
|
879
981
|
}
|
|
982
|
+
}
|
|
983
|
+
};
|
|
880
984
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
985
|
+
for (const {
|
|
986
|
+
name,
|
|
987
|
+
value
|
|
988
|
+
} of exports) {
|
|
989
|
+
addExportToLocalsCode(options.modules.exportLocalsConvention(name), value);
|
|
990
|
+
}
|
|
886
991
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
992
|
+
for (const item of replacements) {
|
|
993
|
+
const {
|
|
994
|
+
replacementName,
|
|
995
|
+
localName
|
|
996
|
+
} = item;
|
|
891
997
|
|
|
892
|
-
|
|
893
|
-
|
|
998
|
+
if (localName) {
|
|
999
|
+
const {
|
|
1000
|
+
importName
|
|
1001
|
+
} = item;
|
|
1002
|
+
localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
|
|
1003
|
+
if (options.modules.namedExport) {
|
|
1004
|
+
return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
|
|
1005
|
+
} else if (options.modules.exportOnlyLocals) {
|
|
1006
|
+
return `" + ${importName}[${JSON.stringify(localName)}] + "`;
|
|
894
1007
|
}
|
|
895
1008
|
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
break;
|
|
903
|
-
}
|
|
1009
|
+
return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
|
|
1010
|
+
});
|
|
1011
|
+
} else {
|
|
1012
|
+
localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
904
1015
|
|
|
905
|
-
|
|
906
|
-
default:
|
|
907
|
-
|
|
908
|
-
break;
|
|
1016
|
+
if (options.modules.exportOnlyLocals) {
|
|
1017
|
+
code += options.modules.namedExport ? localsCode : `${options.esModule ? "export default" : "module.exports ="} {\n${localsCode}\n};\n`;
|
|
1018
|
+
return code;
|
|
909
1019
|
}
|
|
910
|
-
}
|
|
911
1020
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
replacementName,
|
|
915
|
-
localName
|
|
916
|
-
} = item;
|
|
1021
|
+
code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ""}};\n`;
|
|
1022
|
+
}
|
|
917
1023
|
|
|
918
|
-
|
|
919
|
-
const {
|
|
920
|
-
importName
|
|
921
|
-
} = item;
|
|
922
|
-
localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
|
|
923
|
-
if (options.modules.namedExport) {
|
|
924
|
-
return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
|
|
925
|
-
} else if (options.modules.exportOnlyLocals) {
|
|
926
|
-
return `" + ${importName}[${JSON.stringify(localName)}] + "`;
|
|
927
|
-
}
|
|
1024
|
+
const isCSSStyleSheetExport = options.exportType === "css-style-sheet";
|
|
928
1025
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
|
|
933
|
-
}
|
|
1026
|
+
if (isCSSStyleSheetExport) {
|
|
1027
|
+
code += "var ___CSS_LOADER_STYLE_SHEET___ = new CSSStyleSheet();\n";
|
|
1028
|
+
code += "___CSS_LOADER_STYLE_SHEET___.replaceSync(___CSS_LOADER_EXPORT___.toString());\n";
|
|
934
1029
|
}
|
|
935
1030
|
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1031
|
+
let finalExport;
|
|
1032
|
+
|
|
1033
|
+
switch (options.exportType) {
|
|
1034
|
+
case "string":
|
|
1035
|
+
finalExport = "___CSS_LOADER_EXPORT___.toString()";
|
|
1036
|
+
break;
|
|
1037
|
+
|
|
1038
|
+
case "css-style-sheet":
|
|
1039
|
+
finalExport = "___CSS_LOADER_STYLE_SHEET___";
|
|
1040
|
+
break;
|
|
1041
|
+
|
|
1042
|
+
default:
|
|
1043
|
+
case "array":
|
|
1044
|
+
finalExport = "___CSS_LOADER_EXPORT___";
|
|
1045
|
+
break;
|
|
939
1046
|
}
|
|
940
1047
|
|
|
941
|
-
code += options.
|
|
942
|
-
code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
|
|
1048
|
+
code += `${options.esModule ? "export default" : "module.exports ="} ${finalExport};\n`;
|
|
943
1049
|
return code;
|
|
944
1050
|
}
|
|
945
1051
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "css loader module for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/css-loader",
|
|
@@ -55,14 +55,14 @@
|
|
|
55
55
|
"@babel/cli": "^7.14.5",
|
|
56
56
|
"@babel/core": "^7.14.6",
|
|
57
57
|
"@babel/preset-env": "^7.14.7",
|
|
58
|
-
"@commitlint/cli": "^
|
|
59
|
-
"@commitlint/config-conventional": "^
|
|
58
|
+
"@commitlint/cli": "^13.1.0",
|
|
59
|
+
"@commitlint/config-conventional": "^13.1.0",
|
|
60
60
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
61
61
|
"babel-jest": "^27.0.6",
|
|
62
62
|
"cross-env": "^7.0.3",
|
|
63
63
|
"del": "^6.0.0",
|
|
64
|
-
"del-cli": "^4.0.
|
|
65
|
-
"es-check": "^
|
|
64
|
+
"del-cli": "^4.0.1",
|
|
65
|
+
"es-check": "^6.0.0",
|
|
66
66
|
"eslint": "^7.30.0",
|
|
67
67
|
"eslint-config-prettier": "^8.3.0",
|
|
68
68
|
"eslint-plugin-import": "^2.23.4",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"standard-version": "^9.3.1",
|
|
84
84
|
"strip-ansi": "^6.0.0",
|
|
85
85
|
"style-loader": "^3.1.0",
|
|
86
|
-
"stylus": "^0.
|
|
86
|
+
"stylus": "^0.55.0",
|
|
87
87
|
"stylus-loader": "^6.1.0",
|
|
88
88
|
"url-loader": "^4.1.1",
|
|
89
|
-
"webpack": "^5.
|
|
89
|
+
"webpack": "^5.45.1"
|
|
90
90
|
},
|
|
91
91
|
"keywords": [
|
|
92
92
|
"webpack",
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
-
|
|
5
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
-
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
-
|
|
11
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
12
|
-
|
|
13
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
-
|
|
15
|
-
module.exports = function cssWithMappingToString(item) {
|
|
16
|
-
var _item = _slicedToArray(item, 4),
|
|
17
|
-
content = _item[1],
|
|
18
|
-
cssMapping = _item[3];
|
|
19
|
-
|
|
20
|
-
if (!cssMapping) {
|
|
21
|
-
return content;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (typeof btoa === "function") {
|
|
25
|
-
// eslint-disable-next-line no-undef
|
|
26
|
-
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping))));
|
|
27
|
-
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
|
|
28
|
-
var sourceMapping = "/*# ".concat(data, " */");
|
|
29
|
-
var sourceURLs = cssMapping.sources.map(function (source) {
|
|
30
|
-
return "/*# sourceURL=".concat(cssMapping.sourceRoot || "").concat(source, " */");
|
|
31
|
-
});
|
|
32
|
-
return [content].concat(sourceURLs).concat([sourceMapping]).join("\n");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return [content].join("\n");
|
|
36
|
-
};
|