css-loader 6.7.1 → 6.7.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/README.md +51 -19
- package/dist/CssSyntaxError.js +5 -10
- package/dist/Warning.js +5 -8
- package/dist/cjs.js +0 -1
- package/dist/index.js +9 -36
- package/dist/plugins/index.js +0 -4
- package/dist/plugins/postcss-icss-parser.js +4 -24
- package/dist/plugins/postcss-import-parser.js +15 -59
- package/dist/plugins/postcss-url-parser.js +29 -85
- package/dist/runtime/api.js +4 -21
- package/dist/runtime/getUrl.js +5 -8
- package/dist/runtime/sourceMaps.js +0 -3
- package/dist/utils.js +103 -264
- package/package.json +24 -23
|
@@ -4,60 +4,49 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function parseNode(atRule, key, options) {
|
|
15
11
|
// Convert only top-level @import
|
|
16
12
|
if (atRule.parent.type !== "root") {
|
|
17
13
|
return;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
if (atRule.raws && atRule.raws.afterName && atRule.raws.afterName.trim().length > 0) {
|
|
21
16
|
const lastCommentIndex = atRule.raws.afterName.lastIndexOf("/*");
|
|
22
17
|
const matched = atRule.raws.afterName.slice(lastCommentIndex).match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
|
|
23
|
-
|
|
24
18
|
if (matched && matched[2] === "true") {
|
|
25
19
|
return;
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
const prevNode = atRule.prev();
|
|
30
|
-
|
|
31
23
|
if (prevNode && prevNode.type === "comment") {
|
|
32
24
|
const matched = prevNode.text.match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
|
|
33
|
-
|
|
34
25
|
if (matched && matched[2] === "true") {
|
|
35
26
|
return;
|
|
36
27
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
28
|
+
}
|
|
39
29
|
|
|
30
|
+
// Nodes do not exists - `@import url('http://') :root {}`
|
|
40
31
|
if (atRule.nodes) {
|
|
41
32
|
const error = new Error("It looks like you didn't end your @import statement correctly. Child nodes are attached to it.");
|
|
42
33
|
error.node = atRule;
|
|
43
34
|
throw error;
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
const rawParams = atRule.raws && atRule.raws[key] && typeof atRule.raws[key].raw !== "undefined" ? atRule.raws[key].raw : atRule[key];
|
|
47
37
|
const {
|
|
48
38
|
nodes: paramsNodes
|
|
49
|
-
} = (0, _postcssValueParser.default)(rawParams);
|
|
50
|
-
// Invalid type - `@import foo-bar;`
|
|
39
|
+
} = (0, _postcssValueParser.default)(rawParams);
|
|
51
40
|
|
|
41
|
+
// No nodes - `@import ;`
|
|
42
|
+
// Invalid type - `@import foo-bar;`
|
|
52
43
|
if (paramsNodes.length === 0 || paramsNodes[0].type !== "string" && paramsNodes[0].type !== "function") {
|
|
53
44
|
const error = new Error(`Unable to find uri in "${atRule.toString()}"`);
|
|
54
45
|
error.node = atRule;
|
|
55
46
|
throw error;
|
|
56
47
|
}
|
|
57
|
-
|
|
58
48
|
let isStringValue;
|
|
59
49
|
let url;
|
|
60
|
-
|
|
61
50
|
if (paramsNodes[0].type === "string") {
|
|
62
51
|
isStringValue = true;
|
|
63
52
|
url = paramsNodes[0].value;
|
|
@@ -68,47 +57,39 @@ function parseNode(atRule, key, options) {
|
|
|
68
57
|
error.node = atRule;
|
|
69
58
|
throw error;
|
|
70
59
|
}
|
|
71
|
-
|
|
72
60
|
isStringValue = paramsNodes[0].nodes.length !== 0 && paramsNodes[0].nodes[0].type === "string";
|
|
73
61
|
url = isStringValue ? paramsNodes[0].nodes[0].value : _postcssValueParser.default.stringify(paramsNodes[0].nodes);
|
|
74
62
|
}
|
|
75
|
-
|
|
76
63
|
url = (0, _utils.normalizeUrl)(url, isStringValue);
|
|
77
64
|
const {
|
|
78
65
|
requestable,
|
|
79
66
|
needResolve
|
|
80
67
|
} = (0, _utils.isURLRequestable)(url, options);
|
|
81
68
|
let prefix;
|
|
82
|
-
|
|
83
69
|
if (requestable && needResolve) {
|
|
84
70
|
const queryParts = url.split("!");
|
|
85
|
-
|
|
86
71
|
if (queryParts.length > 1) {
|
|
87
72
|
url = queryParts.pop();
|
|
88
73
|
prefix = queryParts.join("!");
|
|
89
74
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
75
|
+
}
|
|
92
76
|
|
|
77
|
+
// Empty url - `@import "";` or `@import url();`
|
|
93
78
|
if (url.trim().length === 0) {
|
|
94
79
|
const error = new Error(`Unable to find uri in "${atRule.toString()}"`);
|
|
95
80
|
error.node = atRule;
|
|
96
81
|
throw error;
|
|
97
82
|
}
|
|
98
|
-
|
|
99
83
|
const additionalNodes = paramsNodes.slice(1);
|
|
100
84
|
let supports;
|
|
101
85
|
let layer;
|
|
102
86
|
let media;
|
|
103
|
-
|
|
104
87
|
if (additionalNodes.length > 0) {
|
|
105
88
|
let nodes = [];
|
|
106
|
-
|
|
107
89
|
for (const node of additionalNodes) {
|
|
108
90
|
nodes.push(node);
|
|
109
91
|
const isLayerFunction = node.type === "function" && node.value.toLowerCase() === "layer";
|
|
110
92
|
const isLayerWord = node.type === "word" && node.value.toLowerCase() === "layer";
|
|
111
|
-
|
|
112
93
|
if (isLayerFunction || isLayerWord) {
|
|
113
94
|
if (isLayerFunction) {
|
|
114
95
|
nodes.splice(nodes.length - 1, 1, ...node.nodes);
|
|
@@ -119,7 +100,6 @@ function parseNode(atRule, key, options) {
|
|
|
119
100
|
unclosed: false
|
|
120
101
|
});
|
|
121
102
|
}
|
|
122
|
-
|
|
123
103
|
layer = _postcssValueParser.default.stringify(nodes).trim().toLowerCase();
|
|
124
104
|
nodes = [];
|
|
125
105
|
} else if (node.type === "function" && node.value.toLowerCase() === "supports") {
|
|
@@ -128,13 +108,12 @@ function parseNode(atRule, key, options) {
|
|
|
128
108
|
nodes = [];
|
|
129
109
|
}
|
|
130
110
|
}
|
|
131
|
-
|
|
132
111
|
if (nodes.length > 0) {
|
|
133
112
|
media = _postcssValueParser.default.stringify(nodes).trim().toLowerCase();
|
|
134
113
|
}
|
|
135
|
-
}
|
|
136
|
-
|
|
114
|
+
}
|
|
137
115
|
|
|
116
|
+
// eslint-disable-next-line consistent-return
|
|
138
117
|
return {
|
|
139
118
|
atRule,
|
|
140
119
|
prefix,
|
|
@@ -146,11 +125,9 @@ function parseNode(atRule, key, options) {
|
|
|
146
125
|
needResolve
|
|
147
126
|
};
|
|
148
127
|
}
|
|
149
|
-
|
|
150
128
|
const plugin = (options = {}) => {
|
|
151
129
|
return {
|
|
152
130
|
postcssPlugin: "postcss-import-parser",
|
|
153
|
-
|
|
154
131
|
prepare(result) {
|
|
155
132
|
const parsedAtRules = [];
|
|
156
133
|
return {
|
|
@@ -160,13 +137,11 @@ const plugin = (options = {}) => {
|
|
|
160
137
|
options.loaderContext.emitError(new Error(atRule.error("'@import' rules are not allowed here and will not be processed").message));
|
|
161
138
|
return;
|
|
162
139
|
}
|
|
163
|
-
|
|
164
140
|
const {
|
|
165
141
|
isSupportDataURL,
|
|
166
142
|
isSupportAbsoluteURL
|
|
167
143
|
} = options;
|
|
168
144
|
let parsedAtRule;
|
|
169
|
-
|
|
170
145
|
try {
|
|
171
146
|
parsedAtRule = parseNode(atRule, "params", {
|
|
172
147
|
isSupportAbsoluteURL,
|
|
@@ -177,21 +152,16 @@ const plugin = (options = {}) => {
|
|
|
177
152
|
node: error.node
|
|
178
153
|
});
|
|
179
154
|
}
|
|
180
|
-
|
|
181
155
|
if (!parsedAtRule) {
|
|
182
156
|
return;
|
|
183
157
|
}
|
|
184
|
-
|
|
185
158
|
parsedAtRules.push(parsedAtRule);
|
|
186
159
|
}
|
|
187
|
-
|
|
188
160
|
},
|
|
189
|
-
|
|
190
161
|
async OnceExit() {
|
|
191
162
|
if (parsedAtRules.length === 0) {
|
|
192
163
|
return;
|
|
193
164
|
}
|
|
194
|
-
|
|
195
165
|
const {
|
|
196
166
|
loaderContext
|
|
197
167
|
} = options;
|
|
@@ -214,30 +184,25 @@ const plugin = (options = {}) => {
|
|
|
214
184
|
supports,
|
|
215
185
|
media
|
|
216
186
|
} = parsedAtRule;
|
|
217
|
-
|
|
218
187
|
if (options.filter) {
|
|
219
188
|
const needKeep = await options.filter(url, media, loaderContext.resourcePath, supports, layer);
|
|
220
|
-
|
|
221
189
|
if (!needKeep) {
|
|
222
190
|
return;
|
|
223
191
|
}
|
|
224
192
|
}
|
|
225
|
-
|
|
226
193
|
if (needResolve) {
|
|
227
194
|
const request = (0, _utils.requestify)(url, loaderContext.rootContext);
|
|
228
195
|
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, loaderContext.context, [...new Set([request, url])]);
|
|
229
|
-
|
|
230
196
|
if (!resolvedUrl) {
|
|
231
197
|
return;
|
|
232
198
|
}
|
|
233
|
-
|
|
234
199
|
if (resolvedUrl === loaderContext.resourcePath) {
|
|
235
200
|
atRule.remove();
|
|
236
201
|
return;
|
|
237
202
|
}
|
|
203
|
+
atRule.remove();
|
|
238
204
|
|
|
239
|
-
|
|
240
|
-
|
|
205
|
+
// eslint-disable-next-line consistent-return
|
|
241
206
|
return {
|
|
242
207
|
url: resolvedUrl,
|
|
243
208
|
layer,
|
|
@@ -247,9 +212,9 @@ const plugin = (options = {}) => {
|
|
|
247
212
|
requestable
|
|
248
213
|
};
|
|
249
214
|
}
|
|
215
|
+
atRule.remove();
|
|
250
216
|
|
|
251
|
-
|
|
252
|
-
|
|
217
|
+
// eslint-disable-next-line consistent-return
|
|
253
218
|
return {
|
|
254
219
|
url,
|
|
255
220
|
layer,
|
|
@@ -260,15 +225,12 @@ const plugin = (options = {}) => {
|
|
|
260
225
|
};
|
|
261
226
|
}));
|
|
262
227
|
const urlToNameMap = new Map();
|
|
263
|
-
|
|
264
228
|
for (let index = 0; index <= resolvedAtRules.length - 1; index++) {
|
|
265
229
|
const resolvedAtRule = resolvedAtRules[index];
|
|
266
|
-
|
|
267
230
|
if (!resolvedAtRule) {
|
|
268
231
|
// eslint-disable-next-line no-continue
|
|
269
232
|
continue;
|
|
270
233
|
}
|
|
271
|
-
|
|
272
234
|
const {
|
|
273
235
|
url,
|
|
274
236
|
requestable,
|
|
@@ -276,7 +238,6 @@ const plugin = (options = {}) => {
|
|
|
276
238
|
supports,
|
|
277
239
|
media
|
|
278
240
|
} = resolvedAtRule;
|
|
279
|
-
|
|
280
241
|
if (!requestable) {
|
|
281
242
|
options.api.push({
|
|
282
243
|
url,
|
|
@@ -284,17 +245,16 @@ const plugin = (options = {}) => {
|
|
|
284
245
|
supports,
|
|
285
246
|
media,
|
|
286
247
|
index
|
|
287
|
-
});
|
|
248
|
+
});
|
|
288
249
|
|
|
250
|
+
// eslint-disable-next-line no-continue
|
|
289
251
|
continue;
|
|
290
252
|
}
|
|
291
|
-
|
|
292
253
|
const {
|
|
293
254
|
prefix
|
|
294
255
|
} = resolvedAtRule;
|
|
295
256
|
const newUrl = prefix ? `${prefix}!${url}` : url;
|
|
296
257
|
let importName = urlToNameMap.get(newUrl);
|
|
297
|
-
|
|
298
258
|
if (!importName) {
|
|
299
259
|
importName = `___CSS_LOADER_AT_RULE_IMPORT_${urlToNameMap.size}___`;
|
|
300
260
|
urlToNameMap.set(newUrl, importName);
|
|
@@ -305,7 +265,6 @@ const plugin = (options = {}) => {
|
|
|
305
265
|
index
|
|
306
266
|
});
|
|
307
267
|
}
|
|
308
|
-
|
|
309
268
|
options.api.push({
|
|
310
269
|
importName,
|
|
311
270
|
layer,
|
|
@@ -315,13 +274,10 @@ const plugin = (options = {}) => {
|
|
|
315
274
|
});
|
|
316
275
|
}
|
|
317
276
|
}
|
|
318
|
-
|
|
319
277
|
};
|
|
320
278
|
}
|
|
321
|
-
|
|
322
279
|
};
|
|
323
280
|
};
|
|
324
|
-
|
|
325
281
|
plugin.postcss = true;
|
|
326
282
|
var _default = plugin;
|
|
327
283
|
exports.default = _default;
|
|
@@ -4,51 +4,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const isUrlFunc = /url/i;
|
|
15
11
|
const isImageSetFunc = /^(?:-webkit-)?image-set$/i;
|
|
16
12
|
const needParseDeclaration = /(?:url|(?:-webkit-)?image-set)\(/i;
|
|
17
|
-
|
|
18
13
|
function getNodeFromUrlFunc(node) {
|
|
19
14
|
return node.nodes && node.nodes[0];
|
|
20
15
|
}
|
|
21
|
-
|
|
22
16
|
function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
|
|
23
17
|
if (index === 0 && typeof inBetween !== "undefined") {
|
|
24
18
|
return inBetween;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
let prevValueNode = nodes[index - 1];
|
|
28
|
-
|
|
29
21
|
if (!prevValueNode) {
|
|
30
22
|
// eslint-disable-next-line consistent-return
|
|
31
23
|
return;
|
|
32
24
|
}
|
|
33
|
-
|
|
34
25
|
if (prevValueNode.type === "space") {
|
|
35
26
|
if (!nodes[index - 2]) {
|
|
36
27
|
// eslint-disable-next-line consistent-return
|
|
37
28
|
return;
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
prevValueNode = nodes[index - 2];
|
|
41
31
|
}
|
|
42
|
-
|
|
43
32
|
if (prevValueNode.type !== "comment") {
|
|
44
33
|
// eslint-disable-next-line consistent-return
|
|
45
34
|
return;
|
|
46
35
|
}
|
|
47
|
-
|
|
48
36
|
const matched = prevValueNode.value.match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
|
|
49
37
|
return matched && matched[2] === "true";
|
|
50
38
|
}
|
|
51
|
-
|
|
52
39
|
function shouldHandleURL(url, declaration, result, options) {
|
|
53
40
|
if (url.length === 0) {
|
|
54
41
|
result.warn(`Unable to find uri in '${declaration.toString()}'`, {
|
|
@@ -59,57 +46,44 @@ function shouldHandleURL(url, declaration, result, options) {
|
|
|
59
46
|
needResolve: false
|
|
60
47
|
};
|
|
61
48
|
}
|
|
62
|
-
|
|
63
49
|
return (0, _utils.isURLRequestable)(url, options);
|
|
64
50
|
}
|
|
65
|
-
|
|
66
51
|
function parseDeclaration(declaration, key, result, options) {
|
|
67
52
|
if (!needParseDeclaration.test(declaration[key])) {
|
|
68
53
|
return;
|
|
69
54
|
}
|
|
70
|
-
|
|
71
55
|
const parsed = (0, _postcssValueParser.default)(declaration.raws && declaration.raws.value && declaration.raws.value.raw ? declaration.raws.value.raw : declaration[key]);
|
|
72
56
|
let inBetween;
|
|
73
|
-
|
|
74
57
|
if (declaration.raws && declaration.raws.between) {
|
|
75
58
|
const lastCommentIndex = declaration.raws.between.lastIndexOf("/*");
|
|
76
59
|
const matched = declaration.raws.between.slice(lastCommentIndex).match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
|
|
77
|
-
|
|
78
60
|
if (matched) {
|
|
79
61
|
inBetween = matched[2] === "true";
|
|
80
62
|
}
|
|
81
63
|
}
|
|
82
|
-
|
|
83
64
|
let isIgnoreOnDeclaration = false;
|
|
84
65
|
const prevNode = declaration.prev();
|
|
85
|
-
|
|
86
66
|
if (prevNode && prevNode.type === "comment") {
|
|
87
67
|
const matched = prevNode.text.match(_utils.WEBPACK_IGNORE_COMMENT_REGEXP);
|
|
88
|
-
|
|
89
68
|
if (matched) {
|
|
90
69
|
isIgnoreOnDeclaration = matched[2] === "true";
|
|
91
70
|
}
|
|
92
71
|
}
|
|
93
|
-
|
|
94
72
|
let needIgnore;
|
|
95
73
|
const parsedURLs = [];
|
|
96
74
|
parsed.walk((valueNode, index, valueNodes) => {
|
|
97
75
|
if (valueNode.type !== "function") {
|
|
98
76
|
return;
|
|
99
77
|
}
|
|
100
|
-
|
|
101
78
|
if (isUrlFunc.test(valueNode.value)) {
|
|
102
79
|
needIgnore = getWebpackIgnoreCommentValue(index, valueNodes, inBetween);
|
|
103
|
-
|
|
104
80
|
if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
|
|
105
81
|
if (needIgnore) {
|
|
106
82
|
// eslint-disable-next-line no-undefined
|
|
107
83
|
needIgnore = undefined;
|
|
108
84
|
}
|
|
109
|
-
|
|
110
85
|
return;
|
|
111
86
|
}
|
|
112
|
-
|
|
113
87
|
const {
|
|
114
88
|
nodes
|
|
115
89
|
} = valueNode;
|
|
@@ -119,21 +93,19 @@ function parseDeclaration(declaration, key, result, options) {
|
|
|
119
93
|
const {
|
|
120
94
|
requestable,
|
|
121
95
|
needResolve
|
|
122
|
-
} = shouldHandleURL(url, declaration, result, options);
|
|
96
|
+
} = shouldHandleURL(url, declaration, result, options);
|
|
123
97
|
|
|
98
|
+
// Do not traverse inside `url`
|
|
124
99
|
if (!requestable) {
|
|
125
100
|
// eslint-disable-next-line consistent-return
|
|
126
101
|
return false;
|
|
127
102
|
}
|
|
128
|
-
|
|
129
103
|
const queryParts = url.split("!");
|
|
130
104
|
let prefix;
|
|
131
|
-
|
|
132
105
|
if (queryParts.length > 1) {
|
|
133
106
|
url = queryParts.pop();
|
|
134
107
|
prefix = queryParts.join("!");
|
|
135
108
|
}
|
|
136
|
-
|
|
137
109
|
parsedURLs.push({
|
|
138
110
|
declaration,
|
|
139
111
|
parsed,
|
|
@@ -142,8 +114,9 @@ function parseDeclaration(declaration, key, result, options) {
|
|
|
142
114
|
url,
|
|
143
115
|
needQuotes: false,
|
|
144
116
|
needResolve
|
|
145
|
-
});
|
|
117
|
+
});
|
|
146
118
|
|
|
119
|
+
// eslint-disable-next-line consistent-return
|
|
147
120
|
return false;
|
|
148
121
|
} else if (isImageSetFunc.test(valueNode.value)) {
|
|
149
122
|
for (const [innerIndex, nNode] of valueNode.nodes.entries()) {
|
|
@@ -151,20 +124,17 @@ function parseDeclaration(declaration, key, result, options) {
|
|
|
151
124
|
type,
|
|
152
125
|
value
|
|
153
126
|
} = nNode;
|
|
154
|
-
|
|
155
127
|
if (type === "function" && isUrlFunc.test(value)) {
|
|
156
128
|
needIgnore = getWebpackIgnoreCommentValue(innerIndex, valueNode.nodes);
|
|
157
|
-
|
|
158
129
|
if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
|
|
159
130
|
if (needIgnore) {
|
|
160
131
|
// eslint-disable-next-line no-undefined
|
|
161
132
|
needIgnore = undefined;
|
|
162
|
-
}
|
|
163
|
-
|
|
133
|
+
}
|
|
164
134
|
|
|
135
|
+
// eslint-disable-next-line no-continue
|
|
165
136
|
continue;
|
|
166
137
|
}
|
|
167
|
-
|
|
168
138
|
const {
|
|
169
139
|
nodes
|
|
170
140
|
} = nNode;
|
|
@@ -174,21 +144,19 @@ function parseDeclaration(declaration, key, result, options) {
|
|
|
174
144
|
const {
|
|
175
145
|
requestable,
|
|
176
146
|
needResolve
|
|
177
|
-
} = shouldHandleURL(url, declaration, result, options);
|
|
147
|
+
} = shouldHandleURL(url, declaration, result, options);
|
|
178
148
|
|
|
149
|
+
// Do not traverse inside `url`
|
|
179
150
|
if (!requestable) {
|
|
180
151
|
// eslint-disable-next-line consistent-return
|
|
181
152
|
return false;
|
|
182
153
|
}
|
|
183
|
-
|
|
184
154
|
const queryParts = url.split("!");
|
|
185
155
|
let prefix;
|
|
186
|
-
|
|
187
156
|
if (queryParts.length > 1) {
|
|
188
157
|
url = queryParts.pop();
|
|
189
158
|
prefix = queryParts.join("!");
|
|
190
159
|
}
|
|
191
|
-
|
|
192
160
|
parsedURLs.push({
|
|
193
161
|
declaration,
|
|
194
162
|
parsed,
|
|
@@ -200,36 +168,32 @@ function parseDeclaration(declaration, key, result, options) {
|
|
|
200
168
|
});
|
|
201
169
|
} else if (type === "string") {
|
|
202
170
|
needIgnore = getWebpackIgnoreCommentValue(innerIndex, valueNode.nodes);
|
|
203
|
-
|
|
204
171
|
if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
|
|
205
172
|
if (needIgnore) {
|
|
206
173
|
// eslint-disable-next-line no-undefined
|
|
207
174
|
needIgnore = undefined;
|
|
208
|
-
}
|
|
209
|
-
|
|
175
|
+
}
|
|
210
176
|
|
|
177
|
+
// eslint-disable-next-line no-continue
|
|
211
178
|
continue;
|
|
212
179
|
}
|
|
213
|
-
|
|
214
180
|
let url = (0, _utils.normalizeUrl)(value, true);
|
|
215
181
|
const {
|
|
216
182
|
requestable,
|
|
217
183
|
needResolve
|
|
218
|
-
} = shouldHandleURL(url, declaration, result, options);
|
|
184
|
+
} = shouldHandleURL(url, declaration, result, options);
|
|
219
185
|
|
|
186
|
+
// Do not traverse inside `url`
|
|
220
187
|
if (!requestable) {
|
|
221
188
|
// eslint-disable-next-line consistent-return
|
|
222
189
|
return false;
|
|
223
190
|
}
|
|
224
|
-
|
|
225
191
|
const queryParts = url.split("!");
|
|
226
192
|
let prefix;
|
|
227
|
-
|
|
228
193
|
if (queryParts.length > 1) {
|
|
229
194
|
url = queryParts.pop();
|
|
230
195
|
prefix = queryParts.join("!");
|
|
231
196
|
}
|
|
232
|
-
|
|
233
197
|
parsedURLs.push({
|
|
234
198
|
declaration,
|
|
235
199
|
parsed,
|
|
@@ -240,21 +204,20 @@ function parseDeclaration(declaration, key, result, options) {
|
|
|
240
204
|
needResolve
|
|
241
205
|
});
|
|
242
206
|
}
|
|
243
|
-
}
|
|
244
|
-
// eslint-disable-next-line consistent-return
|
|
245
|
-
|
|
207
|
+
}
|
|
246
208
|
|
|
209
|
+
// Do not traverse inside `image-set`
|
|
210
|
+
// eslint-disable-next-line consistent-return
|
|
247
211
|
return false;
|
|
248
212
|
}
|
|
249
|
-
});
|
|
213
|
+
});
|
|
250
214
|
|
|
215
|
+
// eslint-disable-next-line consistent-return
|
|
251
216
|
return parsedURLs;
|
|
252
217
|
}
|
|
253
|
-
|
|
254
218
|
const plugin = (options = {}) => {
|
|
255
219
|
return {
|
|
256
220
|
postcssPlugin: "postcss-url-parser",
|
|
257
|
-
|
|
258
221
|
prepare(result) {
|
|
259
222
|
const parsedDeclarations = [];
|
|
260
223
|
return {
|
|
@@ -267,39 +230,31 @@ const plugin = (options = {}) => {
|
|
|
267
230
|
isSupportDataURL,
|
|
268
231
|
isSupportAbsoluteURL
|
|
269
232
|
});
|
|
270
|
-
|
|
271
233
|
if (!parsedURL) {
|
|
272
234
|
return;
|
|
273
235
|
}
|
|
274
|
-
|
|
275
236
|
parsedDeclarations.push(...parsedURL);
|
|
276
237
|
},
|
|
277
|
-
|
|
278
238
|
async OnceExit() {
|
|
279
239
|
if (parsedDeclarations.length === 0) {
|
|
280
240
|
return;
|
|
281
241
|
}
|
|
282
|
-
|
|
283
242
|
const resolvedDeclarations = await Promise.all(parsedDeclarations.map(async parsedDeclaration => {
|
|
284
243
|
const {
|
|
285
244
|
url,
|
|
286
245
|
needResolve
|
|
287
246
|
} = parsedDeclaration;
|
|
288
|
-
|
|
289
247
|
if (options.filter) {
|
|
290
248
|
const needKeep = await options.filter(url);
|
|
291
|
-
|
|
292
249
|
if (!needKeep) {
|
|
293
250
|
// eslint-disable-next-line consistent-return
|
|
294
251
|
return;
|
|
295
252
|
}
|
|
296
253
|
}
|
|
297
|
-
|
|
298
254
|
if (!needResolve) {
|
|
299
255
|
// eslint-disable-next-line consistent-return
|
|
300
256
|
return parsedDeclaration;
|
|
301
257
|
}
|
|
302
|
-
|
|
303
258
|
const splittedUrl = url.split(/(\?)?#/);
|
|
304
259
|
const [pathname, query, hashOrQuery] = splittedUrl;
|
|
305
260
|
let hash = query ? "?" : "";
|
|
@@ -309,24 +264,23 @@ const plugin = (options = {}) => {
|
|
|
309
264
|
rootContext
|
|
310
265
|
} = options;
|
|
311
266
|
const request = (0, _utils.requestify)(pathname, rootContext, Boolean(resolver));
|
|
312
|
-
|
|
313
267
|
if (!resolver) {
|
|
314
268
|
// eslint-disable-next-line consistent-return
|
|
315
|
-
return {
|
|
269
|
+
return {
|
|
270
|
+
...parsedDeclaration,
|
|
316
271
|
url: request,
|
|
317
272
|
hash
|
|
318
273
|
};
|
|
319
274
|
}
|
|
320
|
-
|
|
321
275
|
const resolvedURL = await (0, _utils.resolveRequests)(resolver, options.context, [...new Set([request, url])]);
|
|
322
|
-
|
|
323
276
|
if (!resolvedURL) {
|
|
324
277
|
// eslint-disable-next-line consistent-return
|
|
325
278
|
return;
|
|
326
|
-
}
|
|
327
|
-
|
|
279
|
+
}
|
|
328
280
|
|
|
329
|
-
|
|
281
|
+
// eslint-disable-next-line consistent-return
|
|
282
|
+
return {
|
|
283
|
+
...parsedDeclaration,
|
|
330
284
|
url: resolvedURL,
|
|
331
285
|
hash
|
|
332
286
|
};
|
|
@@ -334,15 +288,12 @@ const plugin = (options = {}) => {
|
|
|
334
288
|
const urlToNameMap = new Map();
|
|
335
289
|
const urlToReplacementMap = new Map();
|
|
336
290
|
let hasUrlImportHelper = false;
|
|
337
|
-
|
|
338
291
|
for (let index = 0; index <= resolvedDeclarations.length - 1; index++) {
|
|
339
292
|
const item = resolvedDeclarations[index];
|
|
340
|
-
|
|
341
293
|
if (!item) {
|
|
342
294
|
// eslint-disable-next-line no-continue
|
|
343
295
|
continue;
|
|
344
296
|
}
|
|
345
|
-
|
|
346
297
|
if (!hasUrlImportHelper) {
|
|
347
298
|
options.imports.push({
|
|
348
299
|
type: "get_url_import",
|
|
@@ -352,14 +303,12 @@ const plugin = (options = {}) => {
|
|
|
352
303
|
});
|
|
353
304
|
hasUrlImportHelper = true;
|
|
354
305
|
}
|
|
355
|
-
|
|
356
306
|
const {
|
|
357
307
|
url,
|
|
358
308
|
prefix
|
|
359
309
|
} = item;
|
|
360
310
|
const newUrl = prefix ? `${prefix}!${url}` : url;
|
|
361
311
|
let importName = urlToNameMap.get(newUrl);
|
|
362
|
-
|
|
363
312
|
if (!importName) {
|
|
364
313
|
importName = `___CSS_LOADER_URL_IMPORT_${urlToNameMap.size}___`;
|
|
365
314
|
urlToNameMap.set(newUrl, importName);
|
|
@@ -370,7 +319,6 @@ const plugin = (options = {}) => {
|
|
|
370
319
|
index
|
|
371
320
|
});
|
|
372
321
|
}
|
|
373
|
-
|
|
374
322
|
const {
|
|
375
323
|
hash,
|
|
376
324
|
needQuotes
|
|
@@ -381,7 +329,6 @@ const plugin = (options = {}) => {
|
|
|
381
329
|
needQuotes
|
|
382
330
|
});
|
|
383
331
|
let replacementName = urlToReplacementMap.get(replacementKey);
|
|
384
|
-
|
|
385
332
|
if (!replacementName) {
|
|
386
333
|
replacementName = `___CSS_LOADER_URL_REPLACEMENT_${urlToReplacementMap.size}___`;
|
|
387
334
|
urlToReplacementMap.set(replacementKey, replacementName);
|
|
@@ -391,23 +338,20 @@ const plugin = (options = {}) => {
|
|
|
391
338
|
hash,
|
|
392
339
|
needQuotes
|
|
393
340
|
});
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
item.node.type = "word"; // eslint-disable-next-line no-param-reassign
|
|
398
|
-
|
|
399
|
-
item.node.value = replacementName; // eslint-disable-next-line no-param-reassign
|
|
341
|
+
}
|
|
400
342
|
|
|
343
|
+
// eslint-disable-next-line no-param-reassign
|
|
344
|
+
item.node.type = "word";
|
|
345
|
+
// eslint-disable-next-line no-param-reassign
|
|
346
|
+
item.node.value = replacementName;
|
|
347
|
+
// eslint-disable-next-line no-param-reassign
|
|
401
348
|
item.declaration.value = item.parsed.toString();
|
|
402
349
|
}
|
|
403
350
|
}
|
|
404
|
-
|
|
405
351
|
};
|
|
406
352
|
}
|
|
407
|
-
|
|
408
353
|
};
|
|
409
354
|
};
|
|
410
|
-
|
|
411
355
|
plugin.postcss = true;
|
|
412
356
|
var _default = plugin;
|
|
413
357
|
exports.default = _default;
|