css-loader 5.2.7 → 6.3.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 +502 -191
- package/dist/index.js +36 -42
- package/dist/options.json +87 -32
- package/dist/plugins/postcss-icss-parser.js +15 -7
- package/dist/plugins/postcss-import-parser.js +75 -11
- package/dist/plugins/postcss-url-parser.js +43 -8
- package/dist/runtime/api.js +53 -17
- package/dist/runtime/getUrl.js +5 -10
- package/dist/runtime/noSourceMaps.js +5 -0
- package/dist/runtime/sourceMaps.js +22 -0
- package/dist/utils.js +432 -163
- package/package.json +27 -29
- package/dist/runtime/cssWithMappingToString.js +0 -36
|
@@ -49,7 +49,7 @@ function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
|
|
|
49
49
|
return matched && matched[2] === "true";
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function shouldHandleURL(url, declaration, result) {
|
|
52
|
+
function shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL) {
|
|
53
53
|
if (url.length === 0) {
|
|
54
54
|
result.warn(`Unable to find uri in '${declaration.toString()}'`, {
|
|
55
55
|
node: declaration
|
|
@@ -57,6 +57,16 @@ function shouldHandleURL(url, declaration, result) {
|
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
if ((0, _utils.isDataUrl)(url) && isSupportDataURLInNewURL) {
|
|
61
|
+
try {
|
|
62
|
+
decodeURIComponent(url);
|
|
63
|
+
} catch (ignoreError) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
60
70
|
if (!(0, _utils.isUrlRequestable)(url)) {
|
|
61
71
|
return false;
|
|
62
72
|
}
|
|
@@ -64,7 +74,7 @@ function shouldHandleURL(url, declaration, result) {
|
|
|
64
74
|
return true;
|
|
65
75
|
}
|
|
66
76
|
|
|
67
|
-
function parseDeclaration(declaration, key, result) {
|
|
77
|
+
function parseDeclaration(declaration, key, result, isSupportDataURLInNewURL) {
|
|
68
78
|
if (!needParseDeclaration.test(declaration[key])) {
|
|
69
79
|
return;
|
|
70
80
|
}
|
|
@@ -118,7 +128,7 @@ function parseDeclaration(declaration, key, result) {
|
|
|
118
128
|
let url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
|
|
119
129
|
url = (0, _utils.normalizeUrl)(url, isStringValue); // Do not traverse inside `url`
|
|
120
130
|
|
|
121
|
-
if (!shouldHandleURL(url, declaration, result)) {
|
|
131
|
+
if (!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)) {
|
|
122
132
|
// eslint-disable-next-line consistent-return
|
|
123
133
|
return false;
|
|
124
134
|
}
|
|
@@ -168,7 +178,7 @@ function parseDeclaration(declaration, key, result) {
|
|
|
168
178
|
let url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
|
|
169
179
|
url = (0, _utils.normalizeUrl)(url, isStringValue); // Do not traverse inside `url`
|
|
170
180
|
|
|
171
|
-
if (!shouldHandleURL(url, declaration, result)) {
|
|
181
|
+
if (!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)) {
|
|
172
182
|
// eslint-disable-next-line consistent-return
|
|
173
183
|
return false;
|
|
174
184
|
}
|
|
@@ -204,7 +214,7 @@ function parseDeclaration(declaration, key, result) {
|
|
|
204
214
|
|
|
205
215
|
let url = (0, _utils.normalizeUrl)(value, true); // Do not traverse inside `url`
|
|
206
216
|
|
|
207
|
-
if (!shouldHandleURL(url, declaration, result)) {
|
|
217
|
+
if (!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)) {
|
|
208
218
|
// eslint-disable-next-line consistent-return
|
|
209
219
|
return false;
|
|
210
220
|
}
|
|
@@ -245,7 +255,10 @@ const plugin = (options = {}) => {
|
|
|
245
255
|
const parsedDeclarations = [];
|
|
246
256
|
return {
|
|
247
257
|
Declaration(declaration) {
|
|
248
|
-
const
|
|
258
|
+
const {
|
|
259
|
+
isSupportDataURLInNewURL
|
|
260
|
+
} = options;
|
|
261
|
+
const parsedURL = parseDeclaration(declaration, "value", result, isSupportDataURLInNewURL);
|
|
249
262
|
|
|
250
263
|
if (!parsedURL) {
|
|
251
264
|
return;
|
|
@@ -268,15 +281,34 @@ const plugin = (options = {}) => {
|
|
|
268
281
|
const needKeep = await options.filter(url);
|
|
269
282
|
|
|
270
283
|
if (!needKeep) {
|
|
284
|
+
// eslint-disable-next-line consistent-return
|
|
271
285
|
return;
|
|
272
286
|
}
|
|
273
287
|
}
|
|
274
288
|
|
|
289
|
+
if ((0, _utils.isDataUrl)(url)) {
|
|
290
|
+
// eslint-disable-next-line consistent-return
|
|
291
|
+
return parsedDeclaration;
|
|
292
|
+
}
|
|
293
|
+
|
|
275
294
|
const splittedUrl = url.split(/(\?)?#/);
|
|
276
295
|
const [pathname, query, hashOrQuery] = splittedUrl;
|
|
277
296
|
let hash = query ? "?" : "";
|
|
278
297
|
hash += hashOrQuery ? `#${hashOrQuery}` : "";
|
|
279
|
-
const
|
|
298
|
+
const {
|
|
299
|
+
needToResolveURL,
|
|
300
|
+
rootContext
|
|
301
|
+
} = options;
|
|
302
|
+
const request = (0, _utils.requestify)(pathname, rootContext, needToResolveURL);
|
|
303
|
+
|
|
304
|
+
if (!needToResolveURL) {
|
|
305
|
+
// eslint-disable-next-line consistent-return
|
|
306
|
+
return { ...parsedDeclaration,
|
|
307
|
+
url: request,
|
|
308
|
+
hash
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
280
312
|
const {
|
|
281
313
|
resolver,
|
|
282
314
|
context
|
|
@@ -284,6 +316,7 @@ const plugin = (options = {}) => {
|
|
|
284
316
|
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, url])]);
|
|
285
317
|
|
|
286
318
|
if (!resolvedUrl) {
|
|
319
|
+
// eslint-disable-next-line consistent-return
|
|
287
320
|
return;
|
|
288
321
|
} // eslint-disable-next-line consistent-return
|
|
289
322
|
|
|
@@ -307,6 +340,7 @@ const plugin = (options = {}) => {
|
|
|
307
340
|
|
|
308
341
|
if (!hasUrlImportHelper) {
|
|
309
342
|
options.imports.push({
|
|
343
|
+
type: "get_url_import",
|
|
310
344
|
importName: "___CSS_LOADER_GET_URL_IMPORT___",
|
|
311
345
|
url: options.urlHandler(require.resolve("../runtime/getUrl.js")),
|
|
312
346
|
index: -1
|
|
@@ -325,8 +359,9 @@ const plugin = (options = {}) => {
|
|
|
325
359
|
importName = `___CSS_LOADER_URL_IMPORT_${urlToNameMap.size}___`;
|
|
326
360
|
urlToNameMap.set(newUrl, importName);
|
|
327
361
|
options.imports.push({
|
|
362
|
+
type: "url",
|
|
328
363
|
importName,
|
|
329
|
-
url: options.urlHandler(newUrl),
|
|
364
|
+
url: options.needToResolveURL ? options.urlHandler(newUrl) : JSON.stringify(newUrl),
|
|
330
365
|
index
|
|
331
366
|
});
|
|
332
367
|
}
|
package/dist/runtime/api.js
CHANGED
|
@@ -4,37 +4,55 @@
|
|
|
4
4
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
5
5
|
Author Tobias Koppers @sokra
|
|
6
6
|
*/
|
|
7
|
-
// css base code, injected by the css-loader
|
|
8
|
-
// eslint-disable-next-line func-names
|
|
9
7
|
module.exports = function (cssWithMappingToString) {
|
|
10
8
|
var list = []; // return the list of modules as css string
|
|
11
9
|
|
|
12
10
|
list.toString = function toString() {
|
|
13
11
|
return this.map(function (item) {
|
|
14
|
-
var content =
|
|
12
|
+
var content = "";
|
|
13
|
+
var needLayer = typeof item[5] !== "undefined";
|
|
14
|
+
|
|
15
|
+
if (item[4]) {
|
|
16
|
+
content += "@supports (".concat(item[4], ") {");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (item[2]) {
|
|
20
|
+
content += "@media ".concat(item[2], " {");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (needLayer) {
|
|
24
|
+
content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
content += cssWithMappingToString(item);
|
|
28
|
+
|
|
29
|
+
if (needLayer) {
|
|
30
|
+
content += "}";
|
|
31
|
+
}
|
|
15
32
|
|
|
16
33
|
if (item[2]) {
|
|
17
|
-
|
|
34
|
+
content += "}";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (item[4]) {
|
|
38
|
+
content += "}";
|
|
18
39
|
}
|
|
19
40
|
|
|
20
41
|
return content;
|
|
21
42
|
}).join("");
|
|
22
43
|
}; // import a list of modules into the list
|
|
23
|
-
// eslint-disable-next-line func-names
|
|
24
44
|
|
|
25
45
|
|
|
26
|
-
list.i = function (modules,
|
|
46
|
+
list.i = function i(modules, media, dedupe, supports, layer) {
|
|
27
47
|
if (typeof modules === "string") {
|
|
28
|
-
|
|
29
|
-
modules = [[null, modules, ""]];
|
|
48
|
+
modules = [[null, modules, undefined]];
|
|
30
49
|
}
|
|
31
50
|
|
|
32
51
|
var alreadyImportedModules = {};
|
|
33
52
|
|
|
34
53
|
if (dedupe) {
|
|
35
|
-
for (var
|
|
36
|
-
|
|
37
|
-
var id = this[i][0];
|
|
54
|
+
for (var _i = 0; _i < this.length; _i++) {
|
|
55
|
+
var id = this[_i][0];
|
|
38
56
|
|
|
39
57
|
if (id != null) {
|
|
40
58
|
alreadyImportedModules[id] = true;
|
|
@@ -42,19 +60,37 @@ module.exports = function (cssWithMappingToString) {
|
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
|
|
45
|
-
for (var
|
|
46
|
-
var item = [].concat(modules[
|
|
63
|
+
for (var _i2 = 0; _i2 < modules.length; _i2++) {
|
|
64
|
+
var item = [].concat(modules[_i2]);
|
|
47
65
|
|
|
48
66
|
if (dedupe && alreadyImportedModules[item[0]]) {
|
|
49
|
-
// eslint-disable-next-line no-continue
|
|
50
67
|
continue;
|
|
51
68
|
}
|
|
52
69
|
|
|
53
|
-
if (
|
|
70
|
+
if (typeof layer !== "undefined") {
|
|
71
|
+
if (typeof item[5] === "undefined") {
|
|
72
|
+
item[5] = layer;
|
|
73
|
+
} else {
|
|
74
|
+
item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
|
|
75
|
+
item[5] = layer;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (media) {
|
|
54
80
|
if (!item[2]) {
|
|
55
|
-
item[2] =
|
|
81
|
+
item[2] = media;
|
|
82
|
+
} else {
|
|
83
|
+
item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
|
|
84
|
+
item[2] = media;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (supports) {
|
|
89
|
+
if (!item[4]) {
|
|
90
|
+
item[4] = "".concat(supports);
|
|
56
91
|
} else {
|
|
57
|
-
item[
|
|
92
|
+
item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
|
|
93
|
+
item[4] = supports;
|
|
58
94
|
}
|
|
59
95
|
}
|
|
60
96
|
|
package/dist/runtime/getUrl.js
CHANGED
|
@@ -2,31 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = function (url, options) {
|
|
4
4
|
if (!options) {
|
|
5
|
-
// eslint-disable-next-line no-param-reassign
|
|
6
5
|
options = {};
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
url = url && url.__esModule ? url.default : url;
|
|
6
|
+
}
|
|
11
7
|
|
|
12
|
-
if (
|
|
8
|
+
if (!url) {
|
|
13
9
|
return url;
|
|
14
|
-
}
|
|
10
|
+
}
|
|
15
11
|
|
|
12
|
+
url = String(url.__esModule ? url.default : url); // If url is already wrapped in quotes, remove them
|
|
16
13
|
|
|
17
14
|
if (/^['"].*['"]$/.test(url)) {
|
|
18
|
-
// eslint-disable-next-line no-param-reassign
|
|
19
15
|
url = url.slice(1, -1);
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
if (options.hash) {
|
|
23
|
-
// eslint-disable-next-line no-param-reassign
|
|
24
19
|
url += options.hash;
|
|
25
20
|
} // Should url be wrapped?
|
|
26
21
|
// See https://drafts.csswg.org/css-values-3/#urls
|
|
27
22
|
|
|
28
23
|
|
|
29
|
-
if (/["'() \t\n]/.test(url) || options.needQuotes) {
|
|
24
|
+
if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
|
|
30
25
|
return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, "\\n"), "\"");
|
|
31
26
|
}
|
|
32
27
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function (item) {
|
|
4
|
+
var content = item[1];
|
|
5
|
+
var cssMapping = item[3];
|
|
6
|
+
|
|
7
|
+
if (!cssMapping) {
|
|
8
|
+
return content;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (typeof btoa === "function") {
|
|
12
|
+
var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping))));
|
|
13
|
+
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
|
|
14
|
+
var sourceMapping = "/*# ".concat(data, " */");
|
|
15
|
+
var sourceURLs = cssMapping.sources.map(function (source) {
|
|
16
|
+
return "/*# sourceURL=".concat(cssMapping.sourceRoot || "").concat(source, " */");
|
|
17
|
+
});
|
|
18
|
+
return [content].concat(sourceURLs).concat([sourceMapping]).join("\n");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return [content].join("\n");
|
|
22
|
+
};
|