css-loader 6.1.0 → 6.5.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/dist/utils.js CHANGED
@@ -3,29 +3,29 @@
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;
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.getImportCode = getImportCode;
19
- exports.getModuleCode = getModuleCode;
20
- exports.getExportCode = getExportCode;
16
+ exports.isDataUrl = isDataUrl;
17
+ exports.isURLRequestable = isURLRequestable;
18
+ exports.normalizeOptions = normalizeOptions;
19
+ exports.normalizeSourceMap = normalizeSourceMap;
20
+ exports.normalizeUrl = normalizeUrl;
21
+ exports.requestify = requestify;
21
22
  exports.resolveRequests = resolveRequests;
22
- exports.isUrlRequestable = isUrlRequestable;
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
 
@@ -55,9 +55,14 @@ function isAbsolutePath(str) {
55
55
 
56
56
  function isRelativePath(str) {
57
57
  return matchRelativePath.test(str);
58
- }
58
+ } // TODO simplify for the next major release
59
+
59
60
 
60
61
  function stringifyRequest(loaderContext, request) {
62
+ if (typeof loaderContext.utils !== "undefined" && typeof loaderContext.utils.contextify === "function") {
63
+ return JSON.stringify(loaderContext.utils.contextify(loaderContext.context, request));
64
+ }
65
+
61
66
  const splitted = request.split("!");
62
67
  const {
63
68
  context
@@ -313,55 +318,62 @@ function escapeLocalIdent(localident) {
313
318
  }
314
319
 
315
320
  function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
316
- let relativeMatchResource = ""; // eslint-disable-next-line no-underscore-dangle
317
-
318
- if (loaderContext._module && loaderContext._module.matchResource) {
319
- relativeMatchResource = `${normalizePath( // eslint-disable-next-line no-underscore-dangle
320
- _path.default.relative(options.context, loaderContext._module.matchResource))}\x00`;
321
- }
322
-
323
- const relativeResourcePath = normalizePath(_path.default.relative(options.context, loaderContext.resourcePath)); // eslint-disable-next-line no-param-reassign
321
+ const {
322
+ context,
323
+ hashSalt
324
+ } = options;
325
+ const {
326
+ resourcePath
327
+ } = loaderContext;
328
+ const relativeResourcePath = normalizePath(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
324
329
 
325
- options.content = `${relativeMatchResource}${relativeResourcePath}\x00${localName}`;
330
+ options.content = `${relativeResourcePath}\x00${localName}`;
326
331
  let {
327
332
  hashFunction,
328
333
  hashDigest,
329
334
  hashDigestLength
330
335
  } = options;
331
- const mathes = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
336
+ const matches = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
332
337
 
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
+ if (matches) {
339
+ const hashName = matches[2] || hashFunction;
340
+ hashFunction = matches[1] || hashFunction;
341
+ hashDigest = matches[3] || hashDigest;
342
+ hashDigestLength = matches[4] || hashDigestLength; // `hash` and `contenthash` are same in `loader-utils` context
338
343
  // let's keep `hash` for backward compatibility
339
344
  // eslint-disable-next-line no-param-reassign
340
345
 
341
346
  localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => hashName === "fullhash" ? "[fullhash]" : "[contenthash]");
342
- } // eslint-disable-next-line no-underscore-dangle
347
+ }
343
348
 
349
+ let localIdentHash = "";
344
350
 
345
- const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
351
+ for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
352
+ // eslint-disable-next-line no-underscore-dangle
353
+ const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
346
354
 
347
- const {
348
- hashSalt
349
- } = options;
355
+ if (hashSalt) {
356
+ hash.update(hashSalt);
357
+ }
350
358
 
351
- if (hashSalt) {
352
- hash.update(hashSalt);
353
- }
359
+ const tierSalt = Buffer.allocUnsafe(4);
360
+ tierSalt.writeUInt32LE(tier);
361
+ hash.update(tierSalt);
362
+ hash.update(options.content);
363
+ localIdentHash = (localIdentHash + hash.digest(hashDigest) // Remove all leading digits
364
+ ).replace(/^\d+/, "") // Replace all slashes with underscores (same as in base64url)
365
+ .replace(/\//g, "_") // Remove everything that is not an alphanumeric or underscore
366
+ .replace(/[^A-Za-z0-9_]+/g, "").slice(0, hashDigestLength);
367
+ } // 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
368
 
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
369
 
358
- const ext = _path.default.extname(loaderContext.resourcePath);
370
+ const ext = _path.default.extname(resourcePath);
359
371
 
360
- const base = _path.default.basename(loaderContext.resourcePath);
372
+ const base = _path.default.basename(resourcePath);
361
373
 
362
374
  const name = base.slice(0, base.length - ext.length);
363
375
  const data = {
364
- filename: _path.default.relative(options.context, loaderContext.resourcePath),
376
+ filename: _path.default.relative(context, resourcePath),
365
377
  contentHash: localIdentHash,
366
378
  chunk: {
367
379
  name,
@@ -372,8 +384,22 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
372
384
 
373
385
  let result = loaderContext._compilation.getPath(localIdentName, data);
374
386
 
387
+ if (/\[folder\]/gi.test(result)) {
388
+ const dirname = _path.default.dirname(resourcePath);
389
+
390
+ let directory = normalizePath(_path.default.relative(context, `${dirname + _path.default.sep}_`));
391
+ directory = directory.substr(0, directory.length - 1);
392
+ let folder = "";
393
+
394
+ if (directory.length > 1) {
395
+ folder = _path.default.basename(directory);
396
+ }
397
+
398
+ result = result.replace(/\[folder\]/gi, () => folder);
399
+ }
400
+
375
401
  if (options.regExp) {
376
- const match = loaderContext.resourcePath.match(options.regExp);
402
+ const match = resourcePath.match(options.regExp);
377
403
 
378
404
  if (match) {
379
405
  match.forEach((matched, i) => {
@@ -462,17 +488,14 @@ function getFilter(filter, resourcePath) {
462
488
  }
463
489
 
464
490
  function getValidLocalName(localName, exportLocalsConvention) {
465
- if (exportLocalsConvention === "dashesOnly") {
466
- return dashesCamelCase(localName);
467
- }
468
-
469
- return camelCase(localName);
491
+ const result = exportLocalsConvention(localName);
492
+ return Array.isArray(result) ? result[0] : result;
470
493
  }
471
494
 
472
495
  const IS_MODULES = /\.module(s)?\.\w+$/i;
473
496
  const IS_ICSS = /\.icss\.\w+$/i;
474
497
 
475
- function getModulesOptions(rawOptions, loaderContext) {
498
+ function getModulesOptions(rawOptions, exportType, loaderContext) {
476
499
  if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
477
500
  return false;
478
501
  }
@@ -502,6 +525,7 @@ function getModulesOptions(rawOptions, loaderContext) {
502
525
  const {
503
526
  outputOptions
504
527
  } = loaderContext._compilation;
528
+ const needNamedExport = exportType === "css-style-sheet" || exportType === "string";
505
529
  const modulesOptions = {
506
530
  auto,
507
531
  mode: "local",
@@ -516,11 +540,44 @@ function getModulesOptions(rawOptions, loaderContext) {
516
540
  localIdentRegExp: undefined,
517
541
  // eslint-disable-next-line no-undefined
518
542
  getLocalIdent: undefined,
519
- namedExport: false,
520
- exportLocalsConvention: rawModulesOptions.namedExport === true && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
543
+ namedExport: needNamedExport || false,
544
+ exportLocalsConvention: (rawModulesOptions.namedExport === true || needNamedExport) && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
521
545
  exportOnlyLocals: false,
522
546
  ...rawModulesOptions
523
547
  };
548
+ let exportLocalsConventionType;
549
+
550
+ if (typeof modulesOptions.exportLocalsConvention === "string") {
551
+ exportLocalsConventionType = modulesOptions.exportLocalsConvention;
552
+
553
+ modulesOptions.exportLocalsConvention = name => {
554
+ switch (exportLocalsConventionType) {
555
+ case "camelCase":
556
+ {
557
+ return [name, camelCase(name)];
558
+ }
559
+
560
+ case "camelCaseOnly":
561
+ {
562
+ return camelCase(name);
563
+ }
564
+
565
+ case "dashes":
566
+ {
567
+ return [name, dashesCamelCase(name)];
568
+ }
569
+
570
+ case "dashesOnly":
571
+ {
572
+ return dashesCamelCase(name);
573
+ }
574
+
575
+ case "asIs":
576
+ default:
577
+ return name;
578
+ }
579
+ };
580
+ }
524
581
 
525
582
  if (typeof modulesOptions.auto === "boolean") {
526
583
  const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
@@ -555,12 +612,22 @@ function getModulesOptions(rawOptions, loaderContext) {
555
612
  modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
556
613
  }
557
614
 
615
+ if (needNamedExport) {
616
+ if (rawOptions.esModule === false) {
617
+ throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'esModules' option to be enabled");
618
+ }
619
+
620
+ if (modulesOptions.namedExport === false) {
621
+ throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'modules.namedExport' option to be enabled");
622
+ }
623
+ }
624
+
558
625
  if (modulesOptions.namedExport === true) {
559
626
  if (rawOptions.esModule === false) {
560
- throw new Error('The "modules.namedExport" option requires the "esModules" option to be enabled');
627
+ throw new Error("The 'modules.namedExport' option requires the 'esModules' option to be enabled");
561
628
  }
562
629
 
563
- if (modulesOptions.exportLocalsConvention !== "camelCaseOnly" && modulesOptions.exportLocalsConvention !== "dashesOnly") {
630
+ if (typeof exportLocalsConventionType === "string" && exportLocalsConventionType !== "camelCaseOnly" && exportLocalsConventionType !== "dashesOnly") {
564
631
  throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
565
632
  }
566
633
  }
@@ -569,14 +636,16 @@ function getModulesOptions(rawOptions, loaderContext) {
569
636
  }
570
637
 
571
638
  function normalizeOptions(rawOptions, loaderContext) {
572
- const modulesOptions = getModulesOptions(rawOptions, loaderContext);
639
+ const exportType = typeof rawOptions.exportType === "undefined" ? "array" : rawOptions.exportType;
640
+ const modulesOptions = getModulesOptions(rawOptions, exportType, loaderContext);
573
641
  return {
574
642
  url: typeof rawOptions.url === "undefined" ? true : rawOptions.url,
575
643
  import: typeof rawOptions.import === "undefined" ? true : rawOptions.import,
576
644
  modules: modulesOptions,
577
645
  sourceMap: typeof rawOptions.sourceMap === "boolean" ? rawOptions.sourceMap : loaderContext.sourceMap,
578
646
  importLoaders: typeof rawOptions.importLoaders === "string" ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
579
- esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule
647
+ esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule,
648
+ exportType
580
649
  };
581
650
  }
582
651
 
@@ -780,6 +849,13 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
780
849
 
781
850
  if (resultMap) {
782
851
  delete resultMap.file;
852
+ /* eslint-disable no-underscore-dangle */
853
+
854
+ if (loaderContext._compilation && loaderContext._compilation.options && loaderContext._compilation.options.devtool && loaderContext._compilation.options.devtool.includes("nosources")) {
855
+ /* eslint-enable no-underscore-dangle */
856
+ delete resultMap.sourcesContent;
857
+ }
858
+
783
859
  resultMap.sourceRoot = "";
784
860
  resultMap.sources = resultMap.sources.map(source => {
785
861
  // Non-standard syntax from `postcss`
@@ -805,22 +881,66 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
805
881
  return JSON.stringify(resultMap);
806
882
  }
807
883
 
884
+ function printParams(media, dedupe, supports, layer) {
885
+ let result = "";
886
+
887
+ if (typeof layer !== "undefined") {
888
+ result = `, ${JSON.stringify(layer)}`;
889
+ }
890
+
891
+ if (typeof supports !== "undefined") {
892
+ result = `, ${JSON.stringify(supports)}${result}`;
893
+ } else if (result.length > 0) {
894
+ result = `, undefined${result}`;
895
+ }
896
+
897
+ if (dedupe) {
898
+ result = `, true${result}`;
899
+ } else if (result.length > 0) {
900
+ result = `, false${result}`;
901
+ }
902
+
903
+ if (media) {
904
+ result = `${JSON.stringify(media)}${result}`;
905
+ } else if (result.length > 0) {
906
+ result = `""${result}`;
907
+ }
908
+
909
+ return result;
910
+ }
911
+
808
912
  function getModuleCode(result, api, replacements, options, loaderContext) {
809
913
  if (options.modules.exportOnlyLocals === true) {
810
914
  return "";
811
915
  }
812
916
 
813
- const sourceMapValue = options.sourceMap ? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}` : "";
917
+ let sourceMapValue = "";
918
+
919
+ if (options.sourceMap) {
920
+ const sourceMap = result.map;
921
+ sourceMapValue = `,${normalizeSourceMapForRuntime(sourceMap, loaderContext)}`;
922
+ }
923
+
814
924
  let code = JSON.stringify(result.css);
815
- let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "function(i){return i[1]}"});\n`;
925
+ let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___"});\n`;
816
926
 
817
927
  for (const item of api) {
818
928
  const {
819
929
  url,
930
+ layer,
931
+ supports,
820
932
  media,
821
933
  dedupe
822
934
  } = item;
823
- 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`;
935
+
936
+ if (url) {
937
+ // eslint-disable-next-line no-undefined
938
+ const printedParam = printParams(media, undefined, supports, layer);
939
+ beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, ${JSON.stringify(`@import url(${url});`)}${printedParam.length > 0 ? `, ${printedParam}` : ""}]);\n`;
940
+ } else {
941
+ const printedParam = printParams(media, dedupe, supports, layer);
942
+ beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${printedParam.length > 0 ? `, ${printedParam}` : ""});\n`;
943
+ }
824
944
  }
825
945
 
826
946
  for (const item of replacements) {
@@ -842,7 +962,14 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
842
962
  beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
843
963
  code = code.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
844
964
  }
845
- }
965
+ } // Indexes description:
966
+ // 0 - module id
967
+ // 1 - CSS code
968
+ // 2 - media
969
+ // 3 - source map
970
+ // 4 - supports
971
+ // 5 - layer
972
+
846
973
 
847
974
  return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
848
975
  }
@@ -851,107 +978,92 @@ function dashesCamelCase(str) {
851
978
  return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
852
979
  }
853
980
 
854
- function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
981
+ function getExportCode(exports, replacements, icssPluginUsed, options) {
855
982
  let code = "// Exports\n";
856
983
 
857
- if (!needToUseIcssPlugin) {
858
- code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
859
- return code;
860
- }
861
-
862
- let localsCode = "";
984
+ if (icssPluginUsed) {
985
+ let localsCode = "";
863
986
 
864
- const addExportToLocalsCode = (name, value) => {
865
- if (options.modules.namedExport) {
866
- localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
867
- } else {
868
- if (localsCode) {
869
- localsCode += `,\n`;
870
- }
871
-
872
- localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
873
- }
874
- };
987
+ const addExportToLocalsCode = (names, value) => {
988
+ const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
875
989
 
876
- for (const {
877
- name,
878
- value
879
- } of exports) {
880
- switch (options.modules.exportLocalsConvention) {
881
- case "camelCase":
882
- {
883
- addExportToLocalsCode(name, value);
884
- const modifiedName = camelCase(name);
885
-
886
- if (modifiedName !== name) {
887
- addExportToLocalsCode(modifiedName, value);
990
+ for (const name of normalizedNames) {
991
+ if (options.modules.namedExport) {
992
+ localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
993
+ } else {
994
+ if (localsCode) {
995
+ localsCode += `,\n`;
888
996
  }
889
997
 
890
- break;
998
+ localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
891
999
  }
1000
+ }
1001
+ };
892
1002
 
893
- case "camelCaseOnly":
894
- {
895
- addExportToLocalsCode(camelCase(name), value);
896
- break;
897
- }
1003
+ for (const {
1004
+ name,
1005
+ value
1006
+ } of exports) {
1007
+ addExportToLocalsCode(options.modules.exportLocalsConvention(name), value);
1008
+ }
898
1009
 
899
- case "dashes":
900
- {
901
- addExportToLocalsCode(name, value);
902
- const modifiedName = dashesCamelCase(name);
1010
+ for (const item of replacements) {
1011
+ const {
1012
+ replacementName,
1013
+ localName
1014
+ } = item;
903
1015
 
904
- if (modifiedName !== name) {
905
- addExportToLocalsCode(modifiedName, value);
1016
+ if (localName) {
1017
+ const {
1018
+ importName
1019
+ } = item;
1020
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
1021
+ if (options.modules.namedExport) {
1022
+ return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
1023
+ } else if (options.modules.exportOnlyLocals) {
1024
+ return `" + ${importName}[${JSON.stringify(localName)}] + "`;
906
1025
  }
907
1026
 
908
- break;
909
- }
910
-
911
- case "dashesOnly":
912
- {
913
- addExportToLocalsCode(dashesCamelCase(name), value);
914
- break;
915
- }
1027
+ return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
1028
+ });
1029
+ } else {
1030
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
1031
+ }
1032
+ }
916
1033
 
917
- case "asIs":
918
- default:
919
- addExportToLocalsCode(name, value);
920
- break;
1034
+ if (options.modules.exportOnlyLocals) {
1035
+ code += options.modules.namedExport ? localsCode : `${options.esModule ? "export default" : "module.exports ="} {\n${localsCode}\n};\n`;
1036
+ return code;
921
1037
  }
922
- }
923
1038
 
924
- for (const item of replacements) {
925
- const {
926
- replacementName,
927
- localName
928
- } = item;
1039
+ code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ""}};\n`;
1040
+ }
929
1041
 
930
- if (localName) {
931
- const {
932
- importName
933
- } = item;
934
- localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
935
- if (options.modules.namedExport) {
936
- return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
937
- } else if (options.modules.exportOnlyLocals) {
938
- return `" + ${importName}[${JSON.stringify(localName)}] + "`;
939
- }
1042
+ const isCSSStyleSheetExport = options.exportType === "css-style-sheet";
940
1043
 
941
- return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
942
- });
943
- } else {
944
- localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
945
- }
1044
+ if (isCSSStyleSheetExport) {
1045
+ code += "var ___CSS_LOADER_STYLE_SHEET___ = new CSSStyleSheet();\n";
1046
+ code += "___CSS_LOADER_STYLE_SHEET___.replaceSync(___CSS_LOADER_EXPORT___.toString());\n";
946
1047
  }
947
1048
 
948
- if (options.modules.exportOnlyLocals) {
949
- code += options.modules.namedExport ? localsCode : `${options.esModule ? "export default" : "module.exports ="} {\n${localsCode}\n};\n`;
950
- return code;
1049
+ let finalExport;
1050
+
1051
+ switch (options.exportType) {
1052
+ case "string":
1053
+ finalExport = "___CSS_LOADER_EXPORT___.toString()";
1054
+ break;
1055
+
1056
+ case "css-style-sheet":
1057
+ finalExport = "___CSS_LOADER_STYLE_SHEET___";
1058
+ break;
1059
+
1060
+ default:
1061
+ case "array":
1062
+ finalExport = "___CSS_LOADER_EXPORT___";
1063
+ break;
951
1064
  }
952
1065
 
953
- code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ""}};\n`;
954
- code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
1066
+ code += `${options.esModule ? "export default" : "module.exports ="} ${finalExport};\n`;
955
1067
  return code;
956
1068
  }
957
1069
 
@@ -967,28 +1079,67 @@ async function resolveRequests(resolve, context, possibleRequests) {
967
1079
  });
968
1080
  }
969
1081
 
970
- function isUrlRequestable(url) {
1082
+ function isURLRequestable(url, options = {}) {
971
1083
  // Protocol-relative URLs
972
1084
  if (/^\/\//.test(url)) {
973
- return false;
1085
+ return {
1086
+ requestable: false,
1087
+ needResolve: false
1088
+ };
1089
+ } // `#` URLs
1090
+
1091
+
1092
+ if (/^#/.test(url)) {
1093
+ return {
1094
+ requestable: false,
1095
+ needResolve: false
1096
+ };
1097
+ } // Data URI
1098
+
1099
+
1100
+ if (isDataUrl(url) && options.isSupportDataURL) {
1101
+ try {
1102
+ decodeURIComponent(url);
1103
+ } catch (ignoreError) {
1104
+ return {
1105
+ requestable: false,
1106
+ needResolve: false
1107
+ };
1108
+ }
1109
+
1110
+ return {
1111
+ requestable: true,
1112
+ needResolve: false
1113
+ };
974
1114
  } // `file:` protocol
975
1115
 
976
1116
 
977
1117
  if (/^file:/i.test(url)) {
978
- return true;
1118
+ return {
1119
+ requestable: true,
1120
+ needResolve: true
1121
+ };
979
1122
  } // Absolute URLs
980
1123
 
981
1124
 
982
1125
  if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !NATIVE_WIN32_PATH.test(url)) {
983
- return false;
984
- } // `#` URLs
985
-
1126
+ if (options.isSupportAbsoluteURL && /^https?:/i.test(url)) {
1127
+ return {
1128
+ requestable: true,
1129
+ needResolve: false
1130
+ };
1131
+ }
986
1132
 
987
- if (/^#/.test(url)) {
988
- return false;
1133
+ return {
1134
+ requestable: false,
1135
+ needResolve: false
1136
+ };
989
1137
  }
990
1138
 
991
- return true;
1139
+ return {
1140
+ requestable: true,
1141
+ needResolve: true
1142
+ };
992
1143
  }
993
1144
 
994
1145
  function sort(a, b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "6.1.0",
3
+ "version": "6.5.0",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -55,15 +55,15 @@
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": "^12.1.4",
59
- "@commitlint/config-conventional": "^12.1.4",
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
64
  "del-cli": "^4.0.1",
65
- "es-check": "^5.2.4",
66
- "eslint": "^7.30.0",
65
+ "es-check": "^6.0.0",
66
+ "eslint": "^8.1.0",
67
67
  "eslint-config-prettier": "^8.3.0",
68
68
  "eslint-plugin-import": "^2.23.4",
69
69
  "file-loader": "^6.2.0",
@@ -83,7 +83,7 @@
83
83
  "standard-version": "^9.3.1",
84
84
  "strip-ansi": "^6.0.0",
85
85
  "style-loader": "^3.1.0",
86
- "stylus": "^0.54.8",
86
+ "stylus": "^0.55.0",
87
87
  "stylus-loader": "^6.1.0",
88
88
  "url-loader": "^4.1.1",
89
89
  "webpack": "^5.45.1"