css-loader 5.2.4 → 6.0.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 +254 -150
- package/dist/index.js +32 -29
- package/dist/options.json +38 -15
- package/dist/plugins/postcss-icss-parser.js +1 -0
- package/dist/plugins/postcss-import-parser.js +6 -0
- package/dist/plugins/postcss-url-parser.js +43 -8
- package/dist/runtime/cssWithMappingToString.js +5 -1
- package/dist/runtime/getUrl.js +6 -7
- package/dist/utils.js +295 -79
- package/package.json +30 -33
- package/CHANGELOG.md +0 -631
package/dist/utils.js
CHANGED
|
@@ -22,14 +22,15 @@ exports.resolveRequests = resolveRequests;
|
|
|
22
22
|
exports.isUrlRequestable = isUrlRequestable;
|
|
23
23
|
exports.sort = sort;
|
|
24
24
|
exports.combineRequests = combineRequests;
|
|
25
|
+
exports.camelCase = camelCase;
|
|
26
|
+
exports.stringifyRequest = stringifyRequest;
|
|
27
|
+
exports.isDataUrl = isDataUrl;
|
|
25
28
|
exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
|
|
26
29
|
|
|
27
30
|
var _url = require("url");
|
|
28
31
|
|
|
29
32
|
var _path = _interopRequireDefault(require("path"));
|
|
30
33
|
|
|
31
|
-
var _loaderUtils = require("loader-utils");
|
|
32
|
-
|
|
33
34
|
var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
|
|
34
35
|
|
|
35
36
|
var _postcssModulesLocalByDefault = _interopRequireDefault(require("postcss-modules-local-by-default"));
|
|
@@ -38,20 +39,137 @@ var _postcssModulesExtractImports = _interopRequireDefault(require("postcss-modu
|
|
|
38
39
|
|
|
39
40
|
var _postcssModulesScope = _interopRequireDefault(require("postcss-modules-scope"));
|
|
40
41
|
|
|
41
|
-
var _camelcase = _interopRequireDefault(require("camelcase"));
|
|
42
|
-
|
|
43
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
44
43
|
|
|
45
44
|
/*
|
|
46
45
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
47
46
|
Author Tobias Koppers @sokra
|
|
48
47
|
*/
|
|
49
|
-
const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
|
|
50
|
-
|
|
48
|
+
const WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
|
|
51
49
|
exports.WEBPACK_IGNORE_COMMENT_REGEXP = WEBPACK_IGNORE_COMMENT_REGEXP;
|
|
50
|
+
const matchRelativePath = /^\.\.?[/\\]/;
|
|
51
|
+
|
|
52
|
+
function isAbsolutePath(str) {
|
|
53
|
+
return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isRelativePath(str) {
|
|
57
|
+
return matchRelativePath.test(str);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function stringifyRequest(loaderContext, request) {
|
|
61
|
+
const splitted = request.split("!");
|
|
62
|
+
const {
|
|
63
|
+
context
|
|
64
|
+
} = loaderContext;
|
|
65
|
+
return JSON.stringify(splitted.map(part => {
|
|
66
|
+
// First, separate singlePath from query, because the query might contain paths again
|
|
67
|
+
const splittedPart = part.match(/^(.*?)(\?.*)/);
|
|
68
|
+
const query = splittedPart ? splittedPart[2] : "";
|
|
69
|
+
let singlePath = splittedPart ? splittedPart[1] : part;
|
|
70
|
+
|
|
71
|
+
if (isAbsolutePath(singlePath) && context) {
|
|
72
|
+
singlePath = _path.default.relative(context, singlePath);
|
|
73
|
+
|
|
74
|
+
if (isAbsolutePath(singlePath)) {
|
|
75
|
+
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
|
76
|
+
// In this case, we leave the path platform-specific without replacing any separators.
|
|
77
|
+
// @see https://github.com/webpack/loader-utils/pull/14
|
|
78
|
+
return singlePath + query;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isRelativePath(singlePath) === false) {
|
|
82
|
+
// Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
|
83
|
+
singlePath = `./${singlePath}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return singlePath.replace(/\\/g, "/") + query;
|
|
88
|
+
}).join("!"));
|
|
89
|
+
} // We can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
93
|
+
const IS_MODULE_REQUEST = /^[^?]*~/;
|
|
94
|
+
|
|
95
|
+
function urlToRequest(url, root) {
|
|
96
|
+
let request;
|
|
97
|
+
|
|
98
|
+
if (IS_NATIVE_WIN32_PATH.test(url)) {
|
|
99
|
+
// absolute windows path, keep it
|
|
100
|
+
request = url;
|
|
101
|
+
} else if (typeof root !== "undefined" && /^\//.test(url)) {
|
|
102
|
+
request = root + url;
|
|
103
|
+
} else if (/^\.\.?\//.test(url)) {
|
|
104
|
+
// A relative url stays
|
|
105
|
+
request = url;
|
|
106
|
+
} else {
|
|
107
|
+
// every other url is threaded like a relative url
|
|
108
|
+
request = `./${url}`;
|
|
109
|
+
} // A `~` makes the url an module
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (IS_MODULE_REQUEST.test(request)) {
|
|
113
|
+
request = request.replace(IS_MODULE_REQUEST, "");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return request;
|
|
117
|
+
} // eslint-disable-next-line no-useless-escape
|
|
118
|
+
|
|
119
|
+
|
|
52
120
|
const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/;
|
|
53
121
|
const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
|
|
54
122
|
|
|
123
|
+
const preserveCamelCase = string => {
|
|
124
|
+
let result = string;
|
|
125
|
+
let isLastCharLower = false;
|
|
126
|
+
let isLastCharUpper = false;
|
|
127
|
+
let isLastLastCharUpper = false;
|
|
128
|
+
|
|
129
|
+
for (let i = 0; i < result.length; i++) {
|
|
130
|
+
const character = result[i];
|
|
131
|
+
|
|
132
|
+
if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
|
|
133
|
+
result = `${result.slice(0, i)}-${result.slice(i)}`;
|
|
134
|
+
isLastCharLower = false;
|
|
135
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
136
|
+
isLastCharUpper = true;
|
|
137
|
+
i += 1;
|
|
138
|
+
} else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
|
|
139
|
+
result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
|
|
140
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
141
|
+
isLastCharUpper = false;
|
|
142
|
+
isLastCharLower = true;
|
|
143
|
+
} else {
|
|
144
|
+
isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
|
|
145
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
146
|
+
isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
function camelCase(input) {
|
|
154
|
+
let result = input.trim();
|
|
155
|
+
|
|
156
|
+
if (result.length === 0) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (result.length === 1) {
|
|
161
|
+
return result.toLowerCase();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const hasUpperCase = result !== result.toLowerCase();
|
|
165
|
+
|
|
166
|
+
if (hasUpperCase) {
|
|
167
|
+
result = preserveCamelCase(result);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return result.replace(/^[_.\- ]+/, "").toLowerCase().replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toUpperCase()).replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toUpperCase());
|
|
171
|
+
}
|
|
172
|
+
|
|
55
173
|
function escape(string) {
|
|
56
174
|
let output = "";
|
|
57
175
|
let counter = 0;
|
|
@@ -204,8 +322,67 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
|
|
|
204
322
|
|
|
205
323
|
const relativeResourcePath = normalizePath(_path.default.relative(options.context, loaderContext.resourcePath)); // eslint-disable-next-line no-param-reassign
|
|
206
324
|
|
|
207
|
-
options.content = `${
|
|
208
|
-
|
|
325
|
+
options.content = `${relativeMatchResource}${relativeResourcePath}\x00${localName}`;
|
|
326
|
+
let {
|
|
327
|
+
hashFunction,
|
|
328
|
+
hashDigest,
|
|
329
|
+
hashDigestLength
|
|
330
|
+
} = options;
|
|
331
|
+
const mathes = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
|
|
332
|
+
|
|
333
|
+
if (mathes) {
|
|
334
|
+
const hashName = mathes[2] || hashFunction;
|
|
335
|
+
hashFunction = mathes[1] || hashFunction;
|
|
336
|
+
hashDigest = mathes[3] || hashDigest;
|
|
337
|
+
hashDigestLength = mathes[4] || hashDigestLength; // `hash` and `contenthash` are same in `loader-utils` context
|
|
338
|
+
// let's keep `hash` for backward compatibility
|
|
339
|
+
// eslint-disable-next-line no-param-reassign
|
|
340
|
+
|
|
341
|
+
localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => hashName === "fullhash" ? "[fullhash]" : "[contenthash]");
|
|
342
|
+
} // eslint-disable-next-line no-underscore-dangle
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
const hash = loaderContext._compiler.webpack.util.createHash(hashFunction);
|
|
346
|
+
|
|
347
|
+
const {
|
|
348
|
+
hashSalt
|
|
349
|
+
} = options;
|
|
350
|
+
|
|
351
|
+
if (hashSalt) {
|
|
352
|
+
hash.update(hashSalt);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
hash.update(options.content);
|
|
356
|
+
const localIdentHash = hash.digest(hashDigest).slice(0, hashDigestLength).replace(/[/+]/g, "_").replace(/^\d/g, "_"); // TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property, also `data` for `getPath` should be looks good without chunk property
|
|
357
|
+
|
|
358
|
+
const ext = _path.default.extname(loaderContext.resourcePath);
|
|
359
|
+
|
|
360
|
+
const base = _path.default.basename(loaderContext.resourcePath);
|
|
361
|
+
|
|
362
|
+
const name = base.slice(0, base.length - ext.length);
|
|
363
|
+
const data = {
|
|
364
|
+
filename: _path.default.relative(options.context, loaderContext.resourcePath),
|
|
365
|
+
contentHash: localIdentHash,
|
|
366
|
+
chunk: {
|
|
367
|
+
name,
|
|
368
|
+
hash: localIdentHash,
|
|
369
|
+
contentHash: localIdentHash
|
|
370
|
+
}
|
|
371
|
+
}; // eslint-disable-next-line no-underscore-dangle
|
|
372
|
+
|
|
373
|
+
return loaderContext._compilation.getPath(localIdentName, data);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function fixedEncodeURIComponent(str) {
|
|
377
|
+
return str.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function isDataUrl(url) {
|
|
381
|
+
if (/^data:/i.test(url)) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return false;
|
|
209
386
|
}
|
|
210
387
|
|
|
211
388
|
const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
|
|
@@ -228,6 +405,11 @@ function normalizeUrl(url, isStringValue) {
|
|
|
228
405
|
|
|
229
406
|
normalizedUrl = unescape(normalizedUrl);
|
|
230
407
|
|
|
408
|
+
if (isDataUrl(url)) {
|
|
409
|
+
// Todo fixedEncodeURIComponent is workaround. Webpack resolver shouldn't handle "!" in dataURL
|
|
410
|
+
return fixedEncodeURIComponent(normalizedUrl);
|
|
411
|
+
}
|
|
412
|
+
|
|
231
413
|
try {
|
|
232
414
|
normalizedUrl = decodeURI(normalizedUrl);
|
|
233
415
|
} catch (error) {// Ignore
|
|
@@ -236,12 +418,25 @@ function normalizeUrl(url, isStringValue) {
|
|
|
236
418
|
return normalizedUrl;
|
|
237
419
|
}
|
|
238
420
|
|
|
239
|
-
function requestify(url, rootContext) {
|
|
240
|
-
if (
|
|
241
|
-
|
|
421
|
+
function requestify(url, rootContext, needToResolveURL = true) {
|
|
422
|
+
if (needToResolveURL) {
|
|
423
|
+
if (/^file:/i.test(url)) {
|
|
424
|
+
return (0, _url.fileURLToPath)(url);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return url.charAt(0) === "/" ? urlToRequest(url, rootContext) : urlToRequest(url);
|
|
242
428
|
}
|
|
243
429
|
|
|
244
|
-
|
|
430
|
+
if (url.charAt(0) === "/" || /^file:/i.test(url)) {
|
|
431
|
+
return url;
|
|
432
|
+
} // A `~` makes the url an module
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
if (IS_MODULE_REQUEST.test(url)) {
|
|
436
|
+
return url.replace(IS_MODULE_REQUEST, "");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return url;
|
|
245
440
|
}
|
|
246
441
|
|
|
247
442
|
function getFilter(filter, resourcePath) {
|
|
@@ -259,80 +454,89 @@ function getValidLocalName(localName, exportLocalsConvention) {
|
|
|
259
454
|
return dashesCamelCase(localName);
|
|
260
455
|
}
|
|
261
456
|
|
|
262
|
-
return (
|
|
457
|
+
return camelCase(localName);
|
|
263
458
|
}
|
|
264
459
|
|
|
265
|
-
const
|
|
266
|
-
const
|
|
460
|
+
const IS_MODULES = /\.module(s)?\.\w+$/i;
|
|
461
|
+
const IS_ICSS = /\.icss\.\w+$/i;
|
|
267
462
|
|
|
268
463
|
function getModulesOptions(rawOptions, loaderContext) {
|
|
464
|
+
if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
|
|
269
468
|
const resourcePath = // eslint-disable-next-line no-underscore-dangle
|
|
270
469
|
loaderContext._module && loaderContext._module.matchResource || loaderContext.resourcePath;
|
|
271
|
-
let
|
|
470
|
+
let auto;
|
|
471
|
+
let rawModulesOptions;
|
|
272
472
|
|
|
273
473
|
if (typeof rawOptions.modules === "undefined") {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
474
|
+
rawModulesOptions = {};
|
|
475
|
+
auto = true;
|
|
476
|
+
} else if (typeof rawOptions.modules === "boolean") {
|
|
477
|
+
rawModulesOptions = {};
|
|
478
|
+
} else if (typeof rawOptions.modules === "string") {
|
|
479
|
+
rawModulesOptions = {
|
|
480
|
+
mode: rawOptions.modules
|
|
481
|
+
};
|
|
482
|
+
} else {
|
|
483
|
+
rawModulesOptions = rawOptions.modules;
|
|
484
|
+
({
|
|
485
|
+
auto
|
|
486
|
+
} = rawModulesOptions);
|
|
487
|
+
} // eslint-disable-next-line no-underscore-dangle
|
|
279
488
|
|
|
280
|
-
if (!isModules && !isIcss) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
} else if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
489
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
490
|
+
const {
|
|
491
|
+
outputOptions
|
|
492
|
+
} = loaderContext._compilation;
|
|
493
|
+
const modulesOptions = {
|
|
494
|
+
auto,
|
|
290
495
|
mode: "local",
|
|
291
496
|
exportGlobals: false,
|
|
292
497
|
localIdentName: "[hash:base64]",
|
|
293
498
|
localIdentContext: loaderContext.rootContext,
|
|
294
|
-
|
|
499
|
+
localIdentHashSalt: outputOptions.hashSalt,
|
|
500
|
+
localIdentHashFunction: outputOptions.hashFunction,
|
|
501
|
+
localIdentHashDigest: outputOptions.hashDigest,
|
|
502
|
+
localIdentHashDigestLength: outputOptions.hashDigestLength,
|
|
295
503
|
// eslint-disable-next-line no-undefined
|
|
296
504
|
localIdentRegExp: undefined,
|
|
297
505
|
// eslint-disable-next-line no-undefined
|
|
298
506
|
getLocalIdent: undefined,
|
|
299
507
|
namedExport: false,
|
|
300
|
-
exportLocalsConvention: "asIs",
|
|
301
|
-
exportOnlyLocals: false
|
|
508
|
+
exportLocalsConvention: rawModulesOptions.namedExport === true && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
|
|
509
|
+
exportOnlyLocals: false,
|
|
510
|
+
...rawModulesOptions
|
|
302
511
|
};
|
|
303
512
|
|
|
304
|
-
if (typeof
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (rawOptions.modules) {
|
|
308
|
-
if (typeof rawOptions.modules.auto === "boolean") {
|
|
309
|
-
const isModules = rawOptions.modules.auto && moduleRegExp.test(resourcePath);
|
|
310
|
-
|
|
311
|
-
if (!isModules) {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
} else if (rawOptions.modules.auto instanceof RegExp) {
|
|
315
|
-
const isModules = rawOptions.modules.auto.test(resourcePath);
|
|
513
|
+
if (typeof modulesOptions.auto === "boolean") {
|
|
514
|
+
const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
|
|
515
|
+
let isIcss;
|
|
316
516
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
} else if (typeof rawOptions.modules.auto === "function") {
|
|
321
|
-
const isModule = rawOptions.modules.auto(resourcePath);
|
|
517
|
+
if (!isModules) {
|
|
518
|
+
isIcss = IS_ICSS.test(resourcePath);
|
|
322
519
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
520
|
+
if (isIcss) {
|
|
521
|
+
modulesOptions.mode = "icss";
|
|
326
522
|
}
|
|
523
|
+
}
|
|
327
524
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
525
|
+
if (!isModules && !isIcss) {
|
|
526
|
+
return false;
|
|
331
527
|
}
|
|
528
|
+
} else if (modulesOptions.auto instanceof RegExp) {
|
|
529
|
+
const isModules = modulesOptions.auto.test(resourcePath);
|
|
332
530
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
531
|
+
if (!isModules) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
} else if (typeof modulesOptions.auto === "function") {
|
|
535
|
+
const isModule = modulesOptions.auto(resourcePath);
|
|
536
|
+
|
|
537
|
+
if (!isModule) {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
336
540
|
}
|
|
337
541
|
|
|
338
542
|
if (typeof modulesOptions.mode === "function") {
|
|
@@ -349,10 +553,6 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
349
553
|
}
|
|
350
554
|
}
|
|
351
555
|
|
|
352
|
-
if (/\[emoji(?::(\d+))?\]/i.test(modulesOptions.localIdentName)) {
|
|
353
|
-
loaderContext.emitWarning("Emoji is deprecated and will be removed in next major release.");
|
|
354
|
-
}
|
|
355
|
-
|
|
356
556
|
return modulesOptions;
|
|
357
557
|
}
|
|
358
558
|
|
|
@@ -393,11 +593,15 @@ function shouldUseURLPlugin(options) {
|
|
|
393
593
|
}
|
|
394
594
|
|
|
395
595
|
function shouldUseModulesPlugins(options) {
|
|
396
|
-
|
|
596
|
+
if (typeof options.modules === "boolean" && options.modules === false) {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return options.modules.mode !== "icss";
|
|
397
601
|
}
|
|
398
602
|
|
|
399
603
|
function shouldUseIcssPlugin(options) {
|
|
400
|
-
return
|
|
604
|
+
return Boolean(options.modules);
|
|
401
605
|
}
|
|
402
606
|
|
|
403
607
|
function getModulesPlugins(options, loaderContext) {
|
|
@@ -406,7 +610,10 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
406
610
|
getLocalIdent,
|
|
407
611
|
localIdentName,
|
|
408
612
|
localIdentContext,
|
|
409
|
-
|
|
613
|
+
localIdentHashSalt,
|
|
614
|
+
localIdentHashFunction,
|
|
615
|
+
localIdentHashDigest,
|
|
616
|
+
localIdentHashDigestLength,
|
|
410
617
|
localIdentRegExp
|
|
411
618
|
} = options.modules;
|
|
412
619
|
let plugins = [];
|
|
@@ -421,7 +628,10 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
421
628
|
if (typeof getLocalIdent !== "undefined") {
|
|
422
629
|
localIdent = getLocalIdent(loaderContext, localIdentName, unescape(exportName), {
|
|
423
630
|
context: localIdentContext,
|
|
424
|
-
|
|
631
|
+
hashSalt: localIdentHashSalt,
|
|
632
|
+
hashFunction: localIdentHashFunction,
|
|
633
|
+
hashDigest: localIdentHashDigest,
|
|
634
|
+
hashDigestLength: localIdentHashDigestLength,
|
|
425
635
|
regExp: localIdentRegExp
|
|
426
636
|
});
|
|
427
637
|
} // A null/undefined value signals that we should invoke the default
|
|
@@ -431,7 +641,10 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
431
641
|
if (typeof localIdent === "undefined" || localIdent === null) {
|
|
432
642
|
localIdent = defaultGetLocalIdent(loaderContext, localIdentName, unescape(exportName), {
|
|
433
643
|
context: localIdentContext,
|
|
434
|
-
|
|
644
|
+
hashSalt: localIdentHashSalt,
|
|
645
|
+
hashFunction: localIdentHashFunction,
|
|
646
|
+
hashDigest: localIdentHashDigest,
|
|
647
|
+
hashDigestLength: localIdentHashDigestLength,
|
|
435
648
|
regExp: localIdentRegExp
|
|
436
649
|
});
|
|
437
650
|
return escapeLocalIdent(localIdent).replace(/\\\[local\\]/gi, exportName);
|
|
@@ -449,7 +662,6 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
449
662
|
return plugins;
|
|
450
663
|
}
|
|
451
664
|
|
|
452
|
-
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
453
665
|
const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
|
|
454
666
|
|
|
455
667
|
function getURLType(source) {
|
|
@@ -533,14 +745,15 @@ function getImportCode(imports, options) {
|
|
|
533
745
|
const {
|
|
534
746
|
importName,
|
|
535
747
|
url,
|
|
536
|
-
icss
|
|
748
|
+
icss,
|
|
749
|
+
type
|
|
537
750
|
} = item;
|
|
538
751
|
|
|
539
752
|
if (options.esModule) {
|
|
540
753
|
if (icss && options.modules.namedExport) {
|
|
541
754
|
code += `import ${options.modules.exportOnlyLocals ? "" : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
|
|
542
755
|
} else {
|
|
543
|
-
code += `import ${importName} from ${url};\n`;
|
|
756
|
+
code += type === "url" ? `var ${importName} = new URL(${url}, import.meta.url);\n` : `import ${importName} from ${url};\n`;
|
|
544
757
|
}
|
|
545
758
|
} else {
|
|
546
759
|
code += `var ${importName} = require(${url});\n`;
|
|
@@ -626,13 +839,19 @@ function dashesCamelCase(str) {
|
|
|
626
839
|
return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
|
|
627
840
|
}
|
|
628
841
|
|
|
629
|
-
function getExportCode(exports, replacements, options) {
|
|
842
|
+
function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
|
|
630
843
|
let code = "// Exports\n";
|
|
844
|
+
|
|
845
|
+
if (!needToUseIcssPlugin) {
|
|
846
|
+
code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
|
|
847
|
+
return code;
|
|
848
|
+
}
|
|
849
|
+
|
|
631
850
|
let localsCode = "";
|
|
632
851
|
|
|
633
852
|
const addExportToLocalsCode = (name, value) => {
|
|
634
853
|
if (options.modules.namedExport) {
|
|
635
|
-
localsCode += `export
|
|
854
|
+
localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
|
636
855
|
} else {
|
|
637
856
|
if (localsCode) {
|
|
638
857
|
localsCode += `,\n`;
|
|
@@ -650,7 +869,7 @@ function getExportCode(exports, replacements, options) {
|
|
|
650
869
|
case "camelCase":
|
|
651
870
|
{
|
|
652
871
|
addExportToLocalsCode(name, value);
|
|
653
|
-
const modifiedName = (
|
|
872
|
+
const modifiedName = camelCase(name);
|
|
654
873
|
|
|
655
874
|
if (modifiedName !== name) {
|
|
656
875
|
addExportToLocalsCode(modifiedName, value);
|
|
@@ -661,7 +880,7 @@ function getExportCode(exports, replacements, options) {
|
|
|
661
880
|
|
|
662
881
|
case "camelCaseOnly":
|
|
663
882
|
{
|
|
664
|
-
addExportToLocalsCode((
|
|
883
|
+
addExportToLocalsCode(camelCase(name), value);
|
|
665
884
|
break;
|
|
666
885
|
}
|
|
667
886
|
|
|
@@ -719,10 +938,7 @@ function getExportCode(exports, replacements, options) {
|
|
|
719
938
|
return code;
|
|
720
939
|
}
|
|
721
940
|
|
|
722
|
-
|
|
723
|
-
code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {\n${localsCode}\n};\n`;
|
|
724
|
-
}
|
|
725
|
-
|
|
941
|
+
code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ""}};\n`;
|
|
726
942
|
code += `${options.esModule ? "export default" : "module.exports ="} ___CSS_LOADER_EXPORT___;\n`;
|
|
727
943
|
return code;
|
|
728
944
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "css loader module for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/css-loader",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"main": "dist/cjs.js",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
16
|
+
"node": ">= 12.13.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "npm run build -- -w",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
|
|
24
24
|
"postbuild": "npm run validate:runtime",
|
|
25
25
|
"commitlint": "commitlint --from=master",
|
|
26
|
-
"security": "npm audit",
|
|
26
|
+
"security": "npm audit --production",
|
|
27
27
|
"lint:prettier": "prettier --list-different .",
|
|
28
28
|
"lint:js": "eslint --cache .",
|
|
29
29
|
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
@@ -32,64 +32,61 @@
|
|
|
32
32
|
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
|
|
33
33
|
"pretest": "npm run lint",
|
|
34
34
|
"test": "npm run test:coverage",
|
|
35
|
-
"prepare": "npm run build",
|
|
35
|
+
"prepare": "husky install && npm run build",
|
|
36
36
|
"release": "standard-version"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"webpack": "^
|
|
42
|
+
"webpack": "^5.0.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"camelcase": "^6.2.0",
|
|
46
45
|
"icss-utils": "^5.1.0",
|
|
47
|
-
"
|
|
48
|
-
"postcss": "^8.2.10",
|
|
46
|
+
"postcss": "^8.2.15",
|
|
49
47
|
"postcss-modules-extract-imports": "^3.0.0",
|
|
50
48
|
"postcss-modules-local-by-default": "^4.0.0",
|
|
51
49
|
"postcss-modules-scope": "^3.0.0",
|
|
52
50
|
"postcss-modules-values": "^4.0.0",
|
|
53
51
|
"postcss-value-parser": "^4.1.0",
|
|
54
|
-
"schema-utils": "^3.0.0",
|
|
55
52
|
"semver": "^7.3.5"
|
|
56
53
|
},
|
|
57
54
|
"devDependencies": {
|
|
58
|
-
"@babel/cli": "^7.
|
|
59
|
-
"@babel/core": "^7.
|
|
60
|
-
"@babel/preset-env": "^7.
|
|
61
|
-
"@commitlint/cli": "^12.1.
|
|
62
|
-
"@commitlint/config-conventional": "^12.1.
|
|
55
|
+
"@babel/cli": "^7.14.5",
|
|
56
|
+
"@babel/core": "^7.14.6",
|
|
57
|
+
"@babel/preset-env": "^7.14.7",
|
|
58
|
+
"@commitlint/cli": "^12.1.4",
|
|
59
|
+
"@commitlint/config-conventional": "^12.1.4",
|
|
63
60
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
64
|
-
"babel-jest": "^
|
|
61
|
+
"babel-jest": "^27.0.6",
|
|
65
62
|
"cross-env": "^7.0.3",
|
|
66
63
|
"del": "^6.0.0",
|
|
67
|
-
"del-cli": "^
|
|
68
|
-
"es-check": "^5.2.
|
|
69
|
-
"eslint": "^7.
|
|
70
|
-
"eslint-config-prettier": "^8.
|
|
71
|
-
"eslint-plugin-import": "^2.
|
|
64
|
+
"del-cli": "^4.0.0",
|
|
65
|
+
"es-check": "^5.2.4",
|
|
66
|
+
"eslint": "^7.30.0",
|
|
67
|
+
"eslint-config-prettier": "^8.3.0",
|
|
68
|
+
"eslint-plugin-import": "^2.23.4",
|
|
72
69
|
"file-loader": "^6.2.0",
|
|
73
|
-
"husky": "^
|
|
74
|
-
"jest": "^
|
|
70
|
+
"husky": "^7.0.1",
|
|
71
|
+
"jest": "^27.0.6",
|
|
75
72
|
"less": "^4.1.1",
|
|
76
|
-
"less-loader": "^
|
|
77
|
-
"lint-staged": "^
|
|
73
|
+
"less-loader": "^10.0.1",
|
|
74
|
+
"lint-staged": "^11.0.1",
|
|
78
75
|
"memfs": "^3.2.2",
|
|
79
|
-
"mini-css-extract-plugin": "^1.
|
|
76
|
+
"mini-css-extract-plugin": "^2.1.0",
|
|
80
77
|
"npm-run-all": "^4.1.5",
|
|
81
|
-
"postcss-loader": "^
|
|
78
|
+
"postcss-loader": "^6.1.1",
|
|
82
79
|
"postcss-preset-env": "^6.7.0",
|
|
83
|
-
"prettier": "^2.
|
|
84
|
-
"sass": "^1.
|
|
85
|
-
"sass-loader": "^
|
|
86
|
-
"standard-version": "^9.
|
|
80
|
+
"prettier": "^2.3.2",
|
|
81
|
+
"sass": "^1.35.2",
|
|
82
|
+
"sass-loader": "^12.1.0",
|
|
83
|
+
"standard-version": "^9.3.1",
|
|
87
84
|
"strip-ansi": "^6.0.0",
|
|
88
|
-
"style-loader": "^
|
|
85
|
+
"style-loader": "^3.1.0",
|
|
89
86
|
"stylus": "^0.54.8",
|
|
90
|
-
"stylus-loader": "^
|
|
87
|
+
"stylus-loader": "^6.1.0",
|
|
91
88
|
"url-loader": "^4.1.1",
|
|
92
|
-
"webpack": "^5.
|
|
89
|
+
"webpack": "^5.44.0"
|
|
93
90
|
},
|
|
94
91
|
"keywords": [
|
|
95
92
|
"webpack",
|