css-loader 4.3.0 → 5.1.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
@@ -21,6 +21,7 @@ exports.getExportCode = getExportCode;
21
21
  exports.resolveRequests = resolveRequests;
22
22
  exports.isUrlRequestable = isUrlRequestable;
23
23
  exports.sort = sort;
24
+ exports.webpackIgnoreCommentRegexp = void 0;
24
25
 
25
26
  var _url = require("url");
26
27
 
@@ -46,9 +47,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
46
47
  MIT License http://www.opensource.org/licenses/mit-license.php
47
48
  Author Tobias Koppers @sokra
48
49
  */
49
- const whitespace = '[\\x20\\t\\r\\n\\f]';
50
- const unescapeRegExp = new RegExp(`\\\\([\\da-f]{1,6}${whitespace}?|(${whitespace})|.)`, 'ig');
50
+ const whitespace = "[\\x20\\t\\r\\n\\f]";
51
+ const unescapeRegExp = new RegExp(`\\\\([\\da-f]{1,6}${whitespace}?|(${whitespace})|.)`, "ig");
51
52
  const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
53
+ const webpackIgnoreCommentRegexp = /webpackIgnore:(\s+)?(true|false)/;
54
+ exports.webpackIgnoreCommentRegexp = webpackIgnoreCommentRegexp;
52
55
 
53
56
  function unescape(str) {
54
57
  return str.replace(unescapeRegExp, (_, escaped, escapedWhitespace) => {
@@ -67,7 +70,7 @@ function unescape(str) {
67
70
  }
68
71
 
69
72
  function normalizePath(file) {
70
- return _path.default.sep === '\\' ? file.replace(/\\/g, '/') : file;
73
+ return _path.default.sep === "\\" ? file.replace(/\\/g, "/") : file;
71
74
  } // eslint-disable-next-line no-control-regex
72
75
 
73
76
 
@@ -75,6 +78,13 @@ const filenameReservedRegex = /[<>:"/\\|?*]/g; // eslint-disable-next-line no-co
75
78
 
76
79
  const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
77
80
 
81
+ function escapeLocalIdent(localident) {
82
+ return (0, _cssesc.default)(localident // For `[hash]` placeholder
83
+ .replace(/^((-?[0-9])|--)/, "_$1").replace(filenameReservedRegex, "-").replace(reControlChars, "-").replace(/\./g, "-"), {
84
+ isIdentifier: true
85
+ });
86
+ }
87
+
78
88
  function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
79
89
  const {
80
90
  context,
@@ -85,27 +95,22 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
85
95
  } = loaderContext;
86
96
  const request = normalizePath(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
87
97
 
88
- options.content = `${hashPrefix + request}\x00${unescape(localName)}`; // Using `[path]` placeholder outputs `/` we need escape their
89
- // Also directories can contains invalid characters for css we need escape their too
90
-
91
- return (0, _cssesc.default)((0, _loaderUtils.interpolateName)(loaderContext, localIdentName, options) // For `[hash]` placeholder
92
- .replace(/^((-?[0-9])|--)/, '_$1').replace(filenameReservedRegex, '-').replace(reControlChars, '-').replace(/\./g, '-'), {
93
- isIdentifier: true
94
- }).replace(/\\\[local\\]/gi, localName);
98
+ options.content = `${hashPrefix + request}\x00${localName}`;
99
+ return (0, _loaderUtils.interpolateName)(loaderContext, localIdentName, options);
95
100
  }
96
101
 
97
102
  function normalizeUrl(url, isStringValue) {
98
103
  let normalizedUrl = url;
99
104
 
100
105
  if (isStringValue && /\\(\n|\r\n|\r|\f)/.test(normalizedUrl)) {
101
- normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, '');
106
+ normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, "");
102
107
  }
103
108
 
104
109
  if (matchNativeWin32Path.test(url)) {
105
- return decodeURIComponent(normalizedUrl);
110
+ return decodeURI(normalizedUrl);
106
111
  }
107
112
 
108
- return decodeURIComponent(unescape(normalizedUrl));
113
+ return decodeURI(unescape(normalizedUrl));
109
114
  }
110
115
 
111
116
  function requestify(url, rootContext) {
@@ -113,12 +118,12 @@ function requestify(url, rootContext) {
113
118
  return (0, _url.fileURLToPath)(url);
114
119
  }
115
120
 
116
- return url.charAt(0) === '/' ? (0, _loaderUtils.urlToRequest)(url, rootContext) : (0, _loaderUtils.urlToRequest)(url);
121
+ return url.charAt(0) === "/" ? (0, _loaderUtils.urlToRequest)(url, rootContext) : (0, _loaderUtils.urlToRequest)(url);
117
122
  }
118
123
 
119
124
  function getFilter(filter, resourcePath) {
120
125
  return (...args) => {
121
- if (typeof filter === 'function') {
126
+ if (typeof filter === "function") {
122
127
  return filter(...args, resourcePath);
123
128
  }
124
129
 
@@ -126,44 +131,59 @@ function getFilter(filter, resourcePath) {
126
131
  };
127
132
  }
128
133
 
129
- const moduleRegExp = /\.module\.\w+$/i;
134
+ function getValidLocalName(localName, exportLocalsConvention) {
135
+ if (exportLocalsConvention === "dashesOnly") {
136
+ return dashesCamelCase(localName);
137
+ }
138
+
139
+ return (0, _camelcase.default)(localName);
140
+ }
141
+
142
+ const moduleRegExp = /\.module(s)?\.\w+$/i;
143
+ const icssRegExp = /\.icss\.\w+$/i;
130
144
 
131
145
  function getModulesOptions(rawOptions, loaderContext) {
132
146
  const {
133
147
  resourcePath
134
148
  } = loaderContext;
149
+ let isIcss;
135
150
 
136
- if (typeof rawOptions.modules === 'undefined') {
151
+ if (typeof rawOptions.modules === "undefined") {
137
152
  const isModules = moduleRegExp.test(resourcePath);
138
153
 
139
154
  if (!isModules) {
155
+ isIcss = icssRegExp.test(resourcePath);
156
+ }
157
+
158
+ if (!isModules && !isIcss) {
140
159
  return false;
141
160
  }
142
- } else if (typeof rawOptions.modules === 'boolean' && rawOptions.modules === false) {
161
+ } else if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
143
162
  return false;
144
163
  }
145
164
 
146
165
  let modulesOptions = {
147
- compileType: rawOptions.icss ? 'icss' : 'module',
166
+ compileType: isIcss ? "icss" : "module",
148
167
  auto: true,
149
- mode: 'local',
168
+ mode: "local",
150
169
  exportGlobals: false,
151
- localIdentName: '[hash:base64]',
170
+ localIdentName: "[hash:base64]",
152
171
  localIdentContext: loaderContext.rootContext,
153
- localIdentHashPrefix: '',
172
+ localIdentHashPrefix: "",
154
173
  // eslint-disable-next-line no-undefined
155
174
  localIdentRegExp: undefined,
156
- getLocalIdent: defaultGetLocalIdent,
175
+ // eslint-disable-next-line no-undefined
176
+ getLocalIdent: undefined,
157
177
  namedExport: false,
158
- exportLocalsConvention: 'asIs',
178
+ exportLocalsConvention: "asIs",
159
179
  exportOnlyLocals: false
160
180
  };
161
181
 
162
- if (typeof rawOptions.modules === 'boolean' || typeof rawOptions.modules === 'string') {
163
- modulesOptions.mode = typeof rawOptions.modules === 'string' ? rawOptions.modules : 'local';
182
+ if (typeof rawOptions.modules === "boolean" || typeof rawOptions.modules === "string") {
183
+ modulesOptions.mode = typeof rawOptions.modules === "string" ? rawOptions.modules : "local";
164
184
  } else {
165
185
  if (rawOptions.modules) {
166
- if (typeof rawOptions.modules.auto === 'boolean') {
186
+ if (typeof rawOptions.modules.auto === "boolean") {
167
187
  const isModules = rawOptions.modules.auto && moduleRegExp.test(resourcePath);
168
188
 
169
189
  if (!isModules) {
@@ -175,7 +195,7 @@ function getModulesOptions(rawOptions, loaderContext) {
175
195
  if (!isModules) {
176
196
  return false;
177
197
  }
178
- } else if (typeof rawOptions.modules.auto === 'function') {
198
+ } else if (typeof rawOptions.modules.auto === "function") {
179
199
  const isModule = rawOptions.modules.auto(resourcePath);
180
200
 
181
201
  if (!isModule) {
@@ -183,8 +203,8 @@ function getModulesOptions(rawOptions, loaderContext) {
183
203
  }
184
204
  }
185
205
 
186
- if (rawOptions.modules.namedExport === true && typeof rawOptions.modules.exportLocalsConvention === 'undefined') {
187
- modulesOptions.exportLocalsConvention = 'camelCaseOnly';
206
+ if (rawOptions.modules.namedExport === true && typeof rawOptions.modules.exportLocalsConvention === "undefined") {
207
+ modulesOptions.exportLocalsConvention = "camelCaseOnly";
188
208
  }
189
209
  }
190
210
 
@@ -193,7 +213,7 @@ function getModulesOptions(rawOptions, loaderContext) {
193
213
  };
194
214
  }
195
215
 
196
- if (typeof modulesOptions.mode === 'function') {
216
+ if (typeof modulesOptions.mode === "function") {
197
217
  modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
198
218
  }
199
219
 
@@ -202,29 +222,27 @@ function getModulesOptions(rawOptions, loaderContext) {
202
222
  throw new Error('The "modules.namedExport" option requires the "esModules" option to be enabled');
203
223
  }
204
224
 
205
- if (modulesOptions.exportLocalsConvention !== 'camelCaseOnly') {
206
- throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly"');
225
+ if (modulesOptions.exportLocalsConvention !== "camelCaseOnly" && modulesOptions.exportLocalsConvention !== "dashesOnly") {
226
+ throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
207
227
  }
208
228
  }
209
229
 
230
+ if (/\[emoji(?::(\d+))?\]/i.test(modulesOptions.localIdentName)) {
231
+ loaderContext.emitWarning("Emoji is deprecated and will be removed in next major release.");
232
+ }
233
+
210
234
  return modulesOptions;
211
235
  }
212
236
 
213
237
  function normalizeOptions(rawOptions, loaderContext) {
214
- if (rawOptions.icss) {
215
- loaderContext.emitWarning(new Error('The "icss" option is deprecated, use "modules.compileType: "icss"" instead'));
216
- }
217
-
218
238
  const modulesOptions = getModulesOptions(rawOptions, loaderContext);
219
239
  return {
220
- url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
221
- import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
240
+ url: typeof rawOptions.url === "undefined" ? true : rawOptions.url,
241
+ import: typeof rawOptions.import === "undefined" ? true : rawOptions.import,
222
242
  modules: modulesOptions,
223
- // TODO remove in the next major release
224
- icss: typeof rawOptions.icss === 'undefined' ? false : rawOptions.icss,
225
- sourceMap: typeof rawOptions.sourceMap === 'boolean' ? rawOptions.sourceMap : loaderContext.sourceMap,
226
- importLoaders: typeof rawOptions.importLoaders === 'string' ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
227
- esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule
243
+ sourceMap: typeof rawOptions.sourceMap === "boolean" ? rawOptions.sourceMap : loaderContext.sourceMap,
244
+ importLoaders: typeof rawOptions.importLoaders === "string" ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
245
+ esModule: typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule
228
246
  };
229
247
  }
230
248
 
@@ -233,7 +251,7 @@ function shouldUseImportPlugin(options) {
233
251
  return false;
234
252
  }
235
253
 
236
- if (typeof options.import === 'boolean') {
254
+ if (typeof options.import === "boolean") {
237
255
  return options.import;
238
256
  }
239
257
 
@@ -245,7 +263,7 @@ function shouldUseURLPlugin(options) {
245
263
  return false;
246
264
  }
247
265
 
248
- if (typeof options.url === 'boolean') {
266
+ if (typeof options.url === "boolean") {
249
267
  return options.url;
250
268
  }
251
269
 
@@ -253,7 +271,7 @@ function shouldUseURLPlugin(options) {
253
271
  }
254
272
 
255
273
  function shouldUseModulesPlugins(options) {
256
- return options.modules.compileType === 'module';
274
+ return options.modules.compileType === "module";
257
275
  }
258
276
 
259
277
  function shouldUseIcssPlugin(options) {
@@ -276,11 +294,28 @@ function getModulesPlugins(options, loaderContext) {
276
294
  mode
277
295
  }), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
278
296
  generateScopedName(exportName) {
279
- return getLocalIdent(loaderContext, localIdentName, exportName, {
280
- context: localIdentContext,
281
- hashPrefix: localIdentHashPrefix,
282
- regExp: localIdentRegExp
283
- });
297
+ let localIdent;
298
+
299
+ if (typeof getLocalIdent !== "undefined") {
300
+ localIdent = getLocalIdent(loaderContext, localIdentName, unescape(exportName), {
301
+ context: localIdentContext,
302
+ hashPrefix: localIdentHashPrefix,
303
+ regExp: localIdentRegExp
304
+ });
305
+ } // A null/undefined value signals that we should invoke the default
306
+ // getLocalIdent method.
307
+
308
+
309
+ if (typeof localIdent === "undefined" || localIdent === null) {
310
+ localIdent = defaultGetLocalIdent(loaderContext, localIdentName, unescape(exportName), {
311
+ context: localIdentContext,
312
+ hashPrefix: localIdentHashPrefix,
313
+ regExp: localIdentRegExp
314
+ });
315
+ return escapeLocalIdent(localIdent).replace(/\\\[local\\]/gi, exportName);
316
+ }
317
+
318
+ return escapeLocalIdent(localIdent);
284
319
  },
285
320
 
286
321
  exportGlobals: options.modules.exportGlobals
@@ -296,26 +331,26 @@ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
296
331
  const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
297
332
 
298
333
  function getURLType(source) {
299
- if (source[0] === '/') {
300
- if (source[1] === '/') {
301
- return 'scheme-relative';
334
+ if (source[0] === "/") {
335
+ if (source[1] === "/") {
336
+ return "scheme-relative";
302
337
  }
303
338
 
304
- return 'path-absolute';
339
+ return "path-absolute";
305
340
  }
306
341
 
307
342
  if (IS_NATIVE_WIN32_PATH.test(source)) {
308
- return 'path-absolute';
343
+ return "path-absolute";
309
344
  }
310
345
 
311
- return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative';
346
+ return ABSOLUTE_SCHEME.test(source) ? "absolute" : "path-relative";
312
347
  }
313
348
 
314
349
  function normalizeSourceMap(map, resourcePath) {
315
350
  let newMap = map; // Some loader emit source map as string
316
351
  // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
317
352
 
318
- if (typeof newMap === 'string') {
353
+ if (typeof newMap === "string") {
319
354
  newMap = JSON.parse(newMap);
320
355
  }
321
356
 
@@ -330,14 +365,14 @@ function normalizeSourceMap(map, resourcePath) {
330
365
  // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
331
366
  newMap.sources = newMap.sources.map(source => {
332
367
  // Non-standard syntax from `postcss`
333
- if (source.indexOf('<') === 0) {
368
+ if (source.indexOf("<") === 0) {
334
369
  return source;
335
370
  }
336
371
 
337
372
  const sourceType = getURLType(source); // Do no touch `scheme-relative` and `absolute` URLs
338
373
 
339
- if (sourceType === 'path-relative' || sourceType === 'path-absolute') {
340
- const absoluteSource = sourceType === 'path-relative' && sourceRoot ? _path.default.resolve(sourceRoot, normalizePath(source)) : normalizePath(source);
374
+ if (sourceType === "path-relative" || sourceType === "path-absolute") {
375
+ const absoluteSource = sourceType === "path-relative" && sourceRoot ? _path.default.resolve(sourceRoot, normalizePath(source)) : normalizePath(source);
341
376
  return _path.default.relative(_path.default.dirname(resourcePath), absoluteSource);
342
377
  }
343
378
 
@@ -359,9 +394,9 @@ function getPreRequester({
359
394
  }
360
395
 
361
396
  if (number === false) {
362
- cache[number] = '';
397
+ cache[number] = "";
363
398
  } else {
364
- const loadersRequest = loaders.slice(loaderIndex, loaderIndex + 1 + (typeof number !== 'number' ? 0 : number)).map(x => x.request).join('!');
399
+ const loadersRequest = loaders.slice(loaderIndex, loaderIndex + 1 + (typeof number !== "number" ? 0 : number)).map(x => x.request).join("!");
365
400
  cache[number] = `-!${loadersRequest}!`;
366
401
  }
367
402
 
@@ -370,7 +405,7 @@ function getPreRequester({
370
405
  }
371
406
 
372
407
  function getImportCode(imports, options) {
373
- let code = '';
408
+ let code = "";
374
409
 
375
410
  for (const item of imports) {
376
411
  const {
@@ -381,7 +416,7 @@ function getImportCode(imports, options) {
381
416
 
382
417
  if (options.esModule) {
383
418
  if (icss && options.modules.namedExport) {
384
- code += `import ${options.modules.exportOnlyLocals ? '' : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
419
+ code += `import ${options.modules.exportOnlyLocals ? "" : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
385
420
  } else {
386
421
  code += `import ${importName} from ${url};\n`;
387
422
  }
@@ -390,7 +425,7 @@ function getImportCode(imports, options) {
390
425
  }
391
426
  }
392
427
 
393
- return code ? `// Imports\n${code}` : '';
428
+ return code ? `// Imports\n${code}` : "";
394
429
  }
395
430
 
396
431
  function normalizeSourceMapForRuntime(map, loaderContext) {
@@ -398,16 +433,16 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
398
433
 
399
434
  if (resultMap) {
400
435
  delete resultMap.file;
401
- resultMap.sourceRoot = '';
436
+ resultMap.sourceRoot = "";
402
437
  resultMap.sources = resultMap.sources.map(source => {
403
438
  // Non-standard syntax from `postcss`
404
- if (source.indexOf('<') === 0) {
439
+ if (source.indexOf("<") === 0) {
405
440
  return source;
406
441
  }
407
442
 
408
443
  const sourceType = getURLType(source);
409
444
 
410
- if (sourceType !== 'path-relative') {
445
+ if (sourceType !== "path-relative") {
411
446
  return source;
412
447
  }
413
448
 
@@ -416,7 +451,7 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
416
451
  const absoluteSource = _path.default.resolve(resourceDirname, source);
417
452
 
418
453
  const contextifyPath = normalizePath(_path.default.relative(loaderContext.rootContext, absoluteSource));
419
- return `webpack://${contextifyPath}`;
454
+ return `webpack://./${contextifyPath}`;
420
455
  });
421
456
  }
422
457
 
@@ -425,12 +460,12 @@ function normalizeSourceMapForRuntime(map, loaderContext) {
425
460
 
426
461
  function getModuleCode(result, api, replacements, options, loaderContext) {
427
462
  if (options.modules.exportOnlyLocals === true) {
428
- return '';
463
+ return "";
429
464
  }
430
465
 
431
- const sourceMapValue = options.sourceMap ? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}` : '';
466
+ const sourceMapValue = options.sourceMap ? `,${normalizeSourceMapForRuntime(result.map, loaderContext)}` : "";
432
467
  let code = JSON.stringify(result.css);
433
- let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap});\n`;
468
+ let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "function(i){return i[1]}"});\n`;
434
469
 
435
470
  for (const item of api) {
436
471
  const {
@@ -438,7 +473,7 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
438
473
  media,
439
474
  dedupe
440
475
  } = item;
441
- 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`;
476
+ 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`;
442
477
  }
443
478
 
444
479
  for (const item of replacements) {
@@ -449,16 +484,16 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
449
484
  } = item;
450
485
 
451
486
  if (localName) {
452
- code = code.replace(new RegExp(replacementName, 'g'), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
487
+ code = code.replace(new RegExp(replacementName, "g"), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
453
488
  } else {
454
489
  const {
455
490
  hash,
456
491
  needQuotes
457
492
  } = item;
458
- const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? 'needQuotes: true' : []);
459
- const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(', ')} }` : '';
493
+ const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? "needQuotes: true" : []);
494
+ const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(", ")} }` : "";
460
495
  beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
461
- code = code.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
496
+ code = code.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
462
497
  }
463
498
  }
464
499
 
@@ -470,12 +505,12 @@ function dashesCamelCase(str) {
470
505
  }
471
506
 
472
507
  function getExportCode(exports, replacements, options) {
473
- let code = '// Exports\n';
474
- let localsCode = '';
508
+ let code = "// Exports\n";
509
+ let localsCode = "";
475
510
 
476
511
  const addExportToLocalsCode = (name, value) => {
477
512
  if (options.modules.namedExport) {
478
- localsCode += `export const ${(0, _camelcase.default)(name)} = ${JSON.stringify(value)};\n`;
513
+ localsCode += `export const ${name} = ${JSON.stringify(value)};\n`;
479
514
  } else {
480
515
  if (localsCode) {
481
516
  localsCode += `,\n`;
@@ -490,7 +525,7 @@ function getExportCode(exports, replacements, options) {
490
525
  value
491
526
  } of exports) {
492
527
  switch (options.modules.exportLocalsConvention) {
493
- case 'camelCase':
528
+ case "camelCase":
494
529
  {
495
530
  addExportToLocalsCode(name, value);
496
531
  const modifiedName = (0, _camelcase.default)(name);
@@ -502,13 +537,13 @@ function getExportCode(exports, replacements, options) {
502
537
  break;
503
538
  }
504
539
 
505
- case 'camelCaseOnly':
540
+ case "camelCaseOnly":
506
541
  {
507
542
  addExportToLocalsCode((0, _camelcase.default)(name), value);
508
543
  break;
509
544
  }
510
545
 
511
- case 'dashes':
546
+ case "dashes":
512
547
  {
513
548
  addExportToLocalsCode(name, value);
514
549
  const modifiedName = dashesCamelCase(name);
@@ -520,13 +555,13 @@ function getExportCode(exports, replacements, options) {
520
555
  break;
521
556
  }
522
557
 
523
- case 'dashesOnly':
558
+ case "dashesOnly":
524
559
  {
525
560
  addExportToLocalsCode(dashesCamelCase(name), value);
526
561
  break;
527
562
  }
528
563
 
529
- case 'asIs':
564
+ case "asIs":
530
565
  default:
531
566
  addExportToLocalsCode(name, value);
532
567
  break;
@@ -543,9 +578,9 @@ function getExportCode(exports, replacements, options) {
543
578
  const {
544
579
  importName
545
580
  } = item;
546
- localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => {
581
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
547
582
  if (options.modules.namedExport) {
548
- return `" + ${importName}_NAMED___[${JSON.stringify((0, _camelcase.default)(localName))}] + "`;
583
+ return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
549
584
  } else if (options.modules.exportOnlyLocals) {
550
585
  return `" + ${importName}[${JSON.stringify(localName)}] + "`;
551
586
  }
@@ -553,12 +588,12 @@ function getExportCode(exports, replacements, options) {
553
588
  return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
554
589
  });
555
590
  } else {
556
- localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
591
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
557
592
  }
558
593
  }
559
594
 
560
595
  if (options.modules.exportOnlyLocals) {
561
- code += options.modules.namedExport ? localsCode : `${options.esModule ? 'export default' : 'module.exports ='} {\n${localsCode}\n};\n`;
596
+ code += options.modules.namedExport ? localsCode : `${options.esModule ? "export default" : "module.exports ="} {\n${localsCode}\n};\n`;
562
597
  return code;
563
598
  }
564
599
 
@@ -566,14 +601,12 @@ function getExportCode(exports, replacements, options) {
566
601
  code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
567
602
  }
568
603
 
569
- code += `${options.esModule ? 'export default' : 'module.exports ='} ___CSS_LOADER_EXPORT___;\n`;
604
+ code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
570
605
  return code;
571
606
  }
572
607
 
573
608
  async function resolveRequests(resolve, context, possibleRequests) {
574
- return resolve(context, possibleRequests[0]).then(result => {
575
- return result;
576
- }).catch(error => {
609
+ return resolve(context, possibleRequests[0]).then(result => result).catch(error => {
577
610
  const [, ...tailPossibleRequests] = possibleRequests;
578
611
 
579
612
  if (tailPossibleRequests.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "4.3.0",
3
+ "version": "5.1.0",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -43,56 +43,56 @@
43
43
  "webpack": "^4.27.0 || ^5.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "camelcase": "^6.0.0",
46
+ "camelcase": "^6.2.0",
47
47
  "cssesc": "^3.0.0",
48
- "icss-utils": "^4.1.1",
48
+ "icss-utils": "^5.1.0",
49
49
  "loader-utils": "^2.0.0",
50
- "postcss": "^7.0.32",
51
- "postcss-modules-extract-imports": "^2.0.0",
52
- "postcss-modules-local-by-default": "^3.0.3",
53
- "postcss-modules-scope": "^2.2.0",
54
- "postcss-modules-values": "^3.0.0",
50
+ "postcss": "^8.2.6",
51
+ "postcss-modules-extract-imports": "^3.0.0",
52
+ "postcss-modules-local-by-default": "^4.0.0",
53
+ "postcss-modules-scope": "^3.0.0",
54
+ "postcss-modules-values": "^4.0.0",
55
55
  "postcss-value-parser": "^4.1.0",
56
- "schema-utils": "^2.7.1",
57
- "semver": "^7.3.2"
56
+ "schema-utils": "^3.0.0",
57
+ "semver": "^7.3.4"
58
58
  },
59
59
  "devDependencies": {
60
- "@babel/cli": "^7.11.6",
61
- "@babel/core": "^7.11.6",
62
- "@babel/preset-env": "^7.11.5",
60
+ "@babel/cli": "^7.12.17",
61
+ "@babel/core": "^7.12.17",
62
+ "@babel/preset-env": "^7.12.17",
63
63
  "@commitlint/cli": "^11.0.0",
64
64
  "@commitlint/config-conventional": "^11.0.0",
65
65
  "@webpack-contrib/defaults": "^6.3.0",
66
66
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
67
- "babel-jest": "^26.1.0",
68
- "cross-env": "^7.0.2",
69
- "del": "^5.1.0",
67
+ "babel-jest": "^26.6.3",
68
+ "cross-env": "^7.0.3",
69
+ "del": "^6.0.0",
70
70
  "del-cli": "^3.0.1",
71
- "es-check": "^5.1.0",
72
- "eslint": "^7.8.1",
73
- "eslint-config-prettier": "^6.11.0",
74
- "eslint-plugin-import": "^2.22.0",
75
- "file-loader": "^6.1.0",
76
- "husky": "^4.3.0",
77
- "jest": "^26.4.2",
78
- "less": "^3.12.2",
79
- "less-loader": "^7.0.1",
80
- "lint-staged": "^10.3.0",
71
+ "es-check": "^5.2.0",
72
+ "eslint": "^7.20.0",
73
+ "eslint-config-prettier": "^7.2.0",
74
+ "eslint-plugin-import": "^2.22.1",
75
+ "file-loader": "^6.2.0",
76
+ "husky": "^4.3.8",
77
+ "jest": "^26.6.3",
78
+ "less": "^4.1.1",
79
+ "less-loader": "^7.1.0",
80
+ "lint-staged": "^10.5.4",
81
81
  "memfs": "^3.2.0",
82
- "mini-css-extract-plugin": "^0.11.0",
82
+ "mini-css-extract-plugin": "^1.3.8",
83
83
  "npm-run-all": "^4.1.5",
84
- "postcss-loader": "^4.0.0",
84
+ "postcss-loader": "^4.0.4",
85
85
  "postcss-preset-env": "^6.7.0",
86
- "prettier": "^2.1.1",
87
- "sass": "^1.26.10",
88
- "sass-loader": "^10.0.2",
89
- "standard-version": "^9.0.0",
86
+ "prettier": "^2.1.2",
87
+ "sass": "^1.32.8",
88
+ "sass-loader": "^10.1.0",
89
+ "standard-version": "^9.1.1",
90
90
  "strip-ansi": "^6.0.0",
91
- "style-loader": "^1.2.1",
91
+ "style-loader": "^2.0.0",
92
92
  "stylus": "^0.54.8",
93
- "stylus-loader": "^3.0.2",
94
- "url-loader": "^4.1.0",
95
- "webpack": "^4.44.1"
93
+ "stylus-loader": "^4.3.0",
94
+ "url-loader": "^4.1.1",
95
+ "webpack": "^5.23.0"
96
96
  },
97
97
  "keywords": [
98
98
  "webpack",