css-loader 4.3.0 → 5.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/CHANGELOG.md +20 -0
- package/README.md +5 -3
- package/dist/CssSyntaxError.js +3 -1
- package/dist/index.js +10 -2
- package/dist/options.json +0 -4
- package/dist/plugins/postcss-icss-parser.js +101 -96
- package/dist/plugins/postcss-import-parser.js +189 -183
- package/dist/plugins/postcss-url-parser.js +198 -194
- package/dist/runtime/api.js +3 -31
- package/dist/runtime/cssWithMappingToString.js +32 -0
- package/dist/utils.js +59 -27
- package/package.json +28 -28
package/dist/utils.js
CHANGED
|
@@ -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,13 +92,8 @@ 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${
|
|
89
|
-
|
|
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) {
|
|
@@ -126,17 +128,31 @@ function getFilter(filter, resourcePath) {
|
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
|
|
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
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
158
|
} else if (typeof rawOptions.modules === 'boolean' && rawOptions.modules === false) {
|
|
@@ -144,7 +160,7 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
let modulesOptions = {
|
|
147
|
-
compileType:
|
|
163
|
+
compileType: isIcss ? 'icss' : 'module',
|
|
148
164
|
auto: true,
|
|
149
165
|
mode: 'local',
|
|
150
166
|
exportGlobals: false,
|
|
@@ -153,7 +169,8 @@ function getModulesOptions(rawOptions, loaderContext) {
|
|
|
153
169
|
localIdentHashPrefix: '',
|
|
154
170
|
// eslint-disable-next-line no-undefined
|
|
155
171
|
localIdentRegExp: undefined,
|
|
156
|
-
|
|
172
|
+
// eslint-disable-next-line no-undefined
|
|
173
|
+
getLocalIdent: undefined,
|
|
157
174
|
namedExport: false,
|
|
158
175
|
exportLocalsConvention: 'asIs',
|
|
159
176
|
exportOnlyLocals: false
|
|
@@ -202,26 +219,24 @@ 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
237
|
url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
|
|
221
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
240
|
sourceMap: typeof rawOptions.sourceMap === 'boolean' ? rawOptions.sourceMap : loaderContext.sourceMap,
|
|
226
241
|
importLoaders: typeof rawOptions.importLoaders === 'string' ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
|
|
227
242
|
esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule
|
|
@@ -276,11 +291,28 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
276
291
|
mode
|
|
277
292
|
}), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
|
|
278
293
|
generateScopedName(exportName) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
|
@@ -430,7 +462,7 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
|
|
|
430
462
|
|
|
431
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 {
|
|
@@ -449,7 +481,7 @@ 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((
|
|
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,
|
|
@@ -475,7 +507,7 @@ function getExportCode(exports, replacements, options) {
|
|
|
475
507
|
|
|
476
508
|
const addExportToLocalsCode = (name, value) => {
|
|
477
509
|
if (options.modules.namedExport) {
|
|
478
|
-
localsCode += `export const ${
|
|
510
|
+
localsCode += `export const ${name} = ${JSON.stringify(value)};\n`;
|
|
479
511
|
} else {
|
|
480
512
|
if (localsCode) {
|
|
481
513
|
localsCode += `,\n`;
|
|
@@ -545,7 +577,7 @@ function getExportCode(exports, replacements, options) {
|
|
|
545
577
|
} = item;
|
|
546
578
|
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => {
|
|
547
579
|
if (options.modules.namedExport) {
|
|
548
|
-
return `" + ${importName}_NAMED___[${JSON.stringify((
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "css loader module for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/css-loader",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"webpack": "^4.27.0 || ^5.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"camelcase": "^6.
|
|
46
|
+
"camelcase": "^6.1.0",
|
|
47
47
|
"cssesc": "^3.0.0",
|
|
48
|
-
"icss-utils": "^
|
|
48
|
+
"icss-utils": "^5.0.0",
|
|
49
49
|
"loader-utils": "^2.0.0",
|
|
50
|
-
"postcss": "^
|
|
51
|
-
"postcss-modules-extract-imports": "^
|
|
52
|
-
"postcss-modules-local-by-default": "^
|
|
53
|
-
"postcss-modules-scope": "^
|
|
54
|
-
"postcss-modules-values": "^
|
|
50
|
+
"postcss": "^8.1.1",
|
|
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": "^
|
|
56
|
+
"schema-utils": "^3.0.0",
|
|
57
57
|
"semver": "^7.3.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
@@ -64,35 +64,35 @@
|
|
|
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.
|
|
67
|
+
"babel-jest": "^26.5.2",
|
|
68
68
|
"cross-env": "^7.0.2",
|
|
69
|
-
"del": "^
|
|
69
|
+
"del": "^6.0.0",
|
|
70
70
|
"del-cli": "^3.0.1",
|
|
71
|
-
"es-check": "^5.1.
|
|
72
|
-
"eslint": "^7.
|
|
73
|
-
"eslint-config-prettier": "^6.
|
|
74
|
-
"eslint-plugin-import": "^2.22.
|
|
75
|
-
"file-loader": "^6.1.
|
|
71
|
+
"es-check": "^5.1.1",
|
|
72
|
+
"eslint": "^7.11.0",
|
|
73
|
+
"eslint-config-prettier": "^6.12.0",
|
|
74
|
+
"eslint-plugin-import": "^2.22.1",
|
|
75
|
+
"file-loader": "^6.1.1",
|
|
76
76
|
"husky": "^4.3.0",
|
|
77
|
-
"jest": "^26.
|
|
77
|
+
"jest": "^26.5.3",
|
|
78
78
|
"less": "^3.12.2",
|
|
79
|
-
"less-loader": "^7.0.
|
|
80
|
-
"lint-staged": "^10.
|
|
79
|
+
"less-loader": "^7.0.2",
|
|
80
|
+
"lint-staged": "^10.4.0",
|
|
81
81
|
"memfs": "^3.2.0",
|
|
82
|
-
"mini-css-extract-plugin": "^0.
|
|
82
|
+
"mini-css-extract-plugin": "^1.0.0",
|
|
83
83
|
"npm-run-all": "^4.1.5",
|
|
84
|
-
"postcss-loader": "^4.0.
|
|
84
|
+
"postcss-loader": "^4.0.4",
|
|
85
85
|
"postcss-preset-env": "^6.7.0",
|
|
86
|
-
"prettier": "^2.1.
|
|
87
|
-
"sass": "^1.
|
|
88
|
-
"sass-loader": "^10.0.
|
|
86
|
+
"prettier": "^2.1.2",
|
|
87
|
+
"sass": "^1.27.0",
|
|
88
|
+
"sass-loader": "^10.0.3",
|
|
89
89
|
"standard-version": "^9.0.0",
|
|
90
90
|
"strip-ansi": "^6.0.0",
|
|
91
|
-
"style-loader": "^
|
|
91
|
+
"style-loader": "^2.0.0",
|
|
92
92
|
"stylus": "^0.54.8",
|
|
93
|
-
"stylus-loader": "^
|
|
94
|
-
"url-loader": "^4.1.
|
|
95
|
-
"webpack": "^
|
|
93
|
+
"stylus-loader": "^4.1.1",
|
|
94
|
+
"url-loader": "^4.1.1",
|
|
95
|
+
"webpack": "^5.0.0"
|
|
96
96
|
},
|
|
97
97
|
"keywords": [
|
|
98
98
|
"webpack",
|