css-loader 4.2.2 → 5.0.2

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