css-loader 4.3.0 → 5.1.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 +41 -0
- package/README.md +177 -89
- package/dist/CssSyntaxError.js +5 -3
- package/dist/Warning.js +2 -2
- package/dist/cjs.js +1 -1
- package/dist/index.js +25 -17
- package/dist/options.json +0 -4
- package/dist/plugins/postcss-icss-parser.js +101 -96
- package/dist/plugins/postcss-import-parser.js +201 -176
- package/dist/plugins/postcss-url-parser.js +283 -191
- package/dist/runtime/api.js +6 -34
- package/dist/runtime/cssWithMappingToString.js +32 -0
- package/dist/runtime/getUrl.js +2 -2
- package/dist/utils.js +128 -95
- package/package.json +36 -36
|
@@ -5,210 +5,235 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _util = require("util");
|
|
9
|
-
|
|
10
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
11
|
-
|
|
12
8
|
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
13
9
|
|
|
14
10
|
var _utils = require("../utils");
|
|
15
11
|
|
|
16
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Convert only top-level @import
|
|
24
|
-
if (atRule.parent.type !== 'root') {
|
|
25
|
-
return;
|
|
26
|
-
} // Nodes do not exists - `@import url('http://') :root {}`
|
|
14
|
+
function visitor(result, parsedResults, node, key) {
|
|
15
|
+
// Convert only top-level @import
|
|
16
|
+
if (node.parent.type !== "root") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
27
19
|
|
|
20
|
+
if (node.raws.afterName && node.raws.afterName.trim().length > 0) {
|
|
21
|
+
const lastCommentIndex = node.raws.afterName.lastIndexOf("/*");
|
|
22
|
+
const matched = node.raws.afterName.slice(lastCommentIndex).match(_utils.webpackIgnoreCommentRegexp);
|
|
28
23
|
|
|
29
|
-
if (
|
|
30
|
-
result.warn("It looks like you didn't end your @import statement correctly. Child nodes are attached to it.", {
|
|
31
|
-
node: atRule
|
|
32
|
-
});
|
|
24
|
+
if (matched && matched[2] === "true") {
|
|
33
25
|
return;
|
|
34
26
|
}
|
|
27
|
+
}
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
nodes: paramsNodes
|
|
38
|
-
} = (0, _postcssValueParser.default)(atRule.params); // No nodes - `@import ;`
|
|
39
|
-
// Invalid type - `@import foo-bar;`
|
|
29
|
+
const prevNode = node.prev();
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
node: atRule
|
|
44
|
-
});
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
31
|
+
if (prevNode && prevNode.type === "comment") {
|
|
32
|
+
const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
let url;
|
|
50
|
-
|
|
51
|
-
if (paramsNodes[0].type === 'string') {
|
|
52
|
-
isStringValue = true;
|
|
53
|
-
url = paramsNodes[0].value;
|
|
54
|
-
} else {
|
|
55
|
-
// Invalid function - `@import nourl(test.css);`
|
|
56
|
-
if (paramsNodes[0].value.toLowerCase() !== 'url') {
|
|
57
|
-
result.warn(`Unable to find uri in "${atRule.toString()}"`, {
|
|
58
|
-
node: atRule
|
|
59
|
-
});
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
isStringValue = paramsNodes[0].nodes.length !== 0 && paramsNodes[0].nodes[0].type === 'string';
|
|
64
|
-
url = isStringValue ? paramsNodes[0].nodes[0].value : _postcssValueParser.default.stringify(paramsNodes[0].nodes);
|
|
65
|
-
} // Empty url - `@import "";` or `@import url();`
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (url.trim().length === 0) {
|
|
69
|
-
result.warn(`Unable to find uri in "${atRule.toString()}"`, {
|
|
70
|
-
node: atRule
|
|
71
|
-
});
|
|
34
|
+
if (matched && matched[2] === "true") {
|
|
72
35
|
return;
|
|
73
36
|
}
|
|
37
|
+
} // Nodes do not exists - `@import url('http://') :root {}`
|
|
74
38
|
|
|
75
|
-
accumulator.push({
|
|
76
|
-
atRule,
|
|
77
|
-
url,
|
|
78
|
-
isStringValue,
|
|
79
|
-
mediaNodes: paramsNodes.slice(1)
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
callback(null, accumulator);
|
|
83
|
-
}
|
|
84
39
|
|
|
85
|
-
|
|
40
|
+
if (node.nodes) {
|
|
41
|
+
result.warn("It looks like you didn't end your @import statement correctly. Child nodes are attached to it.", {
|
|
42
|
+
node
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
86
46
|
|
|
87
|
-
|
|
88
|
-
|
|
47
|
+
const {
|
|
48
|
+
nodes: paramsNodes
|
|
49
|
+
} = (0, _postcssValueParser.default)(node[key]); // No nodes - `@import ;`
|
|
50
|
+
// Invalid type - `@import foo-bar;`
|
|
89
51
|
|
|
90
|
-
if (
|
|
91
|
-
|
|
52
|
+
if (paramsNodes.length === 0 || paramsNodes[0].type !== "string" && paramsNodes[0].type !== "function") {
|
|
53
|
+
result.warn(`Unable to find uri in "${node.toString()}"`, {
|
|
54
|
+
node
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
92
57
|
}
|
|
93
58
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (isRequestable) {
|
|
109
|
-
const queryParts = normalizedUrl.split('!');
|
|
110
|
-
|
|
111
|
-
if (queryParts.length > 1) {
|
|
112
|
-
normalizedUrl = queryParts.pop();
|
|
113
|
-
prefix = queryParts.join('!');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue); // Empty url after normalize - `@import '\
|
|
117
|
-
// \
|
|
118
|
-
// \
|
|
119
|
-
// ';
|
|
120
|
-
|
|
121
|
-
if (normalizedUrl.trim().length === 0) {
|
|
122
|
-
result.warn(`Unable to find uri in "${atRule.toString()}"`, {
|
|
123
|
-
node: atRule
|
|
124
|
-
}); // eslint-disable-next-line no-continue
|
|
125
|
-
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
59
|
+
let isStringValue;
|
|
60
|
+
let url;
|
|
61
|
+
|
|
62
|
+
if (paramsNodes[0].type === "string") {
|
|
63
|
+
isStringValue = true;
|
|
64
|
+
url = paramsNodes[0].value;
|
|
65
|
+
} else {
|
|
66
|
+
// Invalid function - `@import nourl(test.css);`
|
|
67
|
+
if (paramsNodes[0].value.toLowerCase() !== "url") {
|
|
68
|
+
result.warn(`Unable to find uri in "${node.toString()}"`, {
|
|
69
|
+
node
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
128
72
|
}
|
|
129
73
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
media = _postcssValueParser.default.stringify(mediaNodes).trim().toLowerCase();
|
|
134
|
-
}
|
|
74
|
+
isStringValue = paramsNodes[0].nodes.length !== 0 && paramsNodes[0].nodes[0].type === "string";
|
|
75
|
+
url = isStringValue ? paramsNodes[0].nodes[0].value : _postcssValueParser.default.stringify(paramsNodes[0].nodes);
|
|
76
|
+
} // Empty url - `@import "";` or `@import url();`
|
|
135
77
|
|
|
136
|
-
if (options.filter && !options.filter(normalizedUrl, media)) {
|
|
137
|
-
// eslint-disable-next-line no-continue
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
78
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const {
|
|
147
|
-
resolver,
|
|
148
|
-
context
|
|
149
|
-
} = options;
|
|
150
|
-
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, normalizedUrl])]);
|
|
151
|
-
return {
|
|
152
|
-
url: resolvedUrl,
|
|
153
|
-
media,
|
|
154
|
-
prefix,
|
|
155
|
-
isRequestable
|
|
156
|
-
};
|
|
157
|
-
})());
|
|
158
|
-
} else {
|
|
159
|
-
tasks.push({
|
|
160
|
-
url,
|
|
161
|
-
media,
|
|
162
|
-
prefix,
|
|
163
|
-
isRequestable
|
|
164
|
-
});
|
|
165
|
-
}
|
|
79
|
+
if (url.trim().length === 0) {
|
|
80
|
+
result.warn(`Unable to find uri in "${node.toString()}"`, {
|
|
81
|
+
node
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
166
84
|
}
|
|
167
85
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
} = results[index];
|
|
176
|
-
|
|
177
|
-
if (isRequestable) {
|
|
178
|
-
const {
|
|
179
|
-
prefix
|
|
180
|
-
} = results[index];
|
|
181
|
-
const newUrl = prefix ? `${prefix}!${url}` : url;
|
|
182
|
-
const importKey = newUrl;
|
|
183
|
-
let importName = imports.get(importKey);
|
|
184
|
-
|
|
185
|
-
if (!importName) {
|
|
186
|
-
importName = `___CSS_LOADER_AT_RULE_IMPORT_${imports.size}___`;
|
|
187
|
-
imports.set(importKey, importName);
|
|
188
|
-
options.imports.push({
|
|
189
|
-
importName,
|
|
190
|
-
url: options.urlHandler(newUrl),
|
|
191
|
-
index
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
options.api.push({
|
|
196
|
-
importName,
|
|
197
|
-
media,
|
|
198
|
-
index
|
|
199
|
-
}); // eslint-disable-next-line no-continue
|
|
200
|
-
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
86
|
+
parsedResults.push({
|
|
87
|
+
node,
|
|
88
|
+
url,
|
|
89
|
+
isStringValue,
|
|
90
|
+
mediaNodes: paramsNodes.slice(1)
|
|
91
|
+
});
|
|
92
|
+
}
|
|
203
93
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
94
|
+
const plugin = (options = {}) => {
|
|
95
|
+
return {
|
|
96
|
+
postcssPlugin: "postcss-import-parser",
|
|
97
|
+
|
|
98
|
+
prepare(result) {
|
|
99
|
+
const parsedResults = [];
|
|
100
|
+
return {
|
|
101
|
+
AtRule: {
|
|
102
|
+
import(atRule) {
|
|
103
|
+
visitor(result, parsedResults, atRule, "params");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
async OnceExit() {
|
|
109
|
+
if (parsedResults.length === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const imports = new Map();
|
|
114
|
+
const tasks = [];
|
|
115
|
+
|
|
116
|
+
for (const parsedResult of parsedResults) {
|
|
117
|
+
const {
|
|
118
|
+
node,
|
|
119
|
+
url,
|
|
120
|
+
isStringValue,
|
|
121
|
+
mediaNodes
|
|
122
|
+
} = parsedResult;
|
|
123
|
+
let normalizedUrl = url;
|
|
124
|
+
let prefix = "";
|
|
125
|
+
const isRequestable = (0, _utils.isUrlRequestable)(normalizedUrl);
|
|
126
|
+
|
|
127
|
+
if (isRequestable) {
|
|
128
|
+
const queryParts = normalizedUrl.split("!");
|
|
129
|
+
|
|
130
|
+
if (queryParts.length > 1) {
|
|
131
|
+
normalizedUrl = queryParts.pop();
|
|
132
|
+
prefix = queryParts.join("!");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue); // Empty url after normalize - `@import '\
|
|
136
|
+
// \
|
|
137
|
+
// \
|
|
138
|
+
// ';
|
|
139
|
+
|
|
140
|
+
if (normalizedUrl.trim().length === 0) {
|
|
141
|
+
result.warn(`Unable to find uri in "${node.toString()}"`, {
|
|
142
|
+
node
|
|
143
|
+
}); // eslint-disable-next-line no-continue
|
|
144
|
+
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let media;
|
|
150
|
+
|
|
151
|
+
if (mediaNodes.length > 0) {
|
|
152
|
+
media = _postcssValueParser.default.stringify(mediaNodes).trim().toLowerCase();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (options.filter && !options.filter(normalizedUrl, media)) {
|
|
156
|
+
// eslint-disable-next-line no-continue
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
node.remove();
|
|
161
|
+
|
|
162
|
+
if (isRequestable) {
|
|
163
|
+
const request = (0, _utils.requestify)(normalizedUrl, options.rootContext);
|
|
164
|
+
tasks.push((async () => {
|
|
165
|
+
const {
|
|
166
|
+
resolver,
|
|
167
|
+
context
|
|
168
|
+
} = options;
|
|
169
|
+
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, normalizedUrl])]);
|
|
170
|
+
return {
|
|
171
|
+
url: resolvedUrl,
|
|
172
|
+
media,
|
|
173
|
+
prefix,
|
|
174
|
+
isRequestable
|
|
175
|
+
};
|
|
176
|
+
})());
|
|
177
|
+
} else {
|
|
178
|
+
tasks.push({
|
|
179
|
+
url,
|
|
180
|
+
media,
|
|
181
|
+
prefix,
|
|
182
|
+
isRequestable
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const results = await Promise.all(tasks);
|
|
188
|
+
|
|
189
|
+
for (let index = 0; index <= results.length - 1; index++) {
|
|
190
|
+
const {
|
|
191
|
+
url,
|
|
192
|
+
isRequestable,
|
|
193
|
+
media
|
|
194
|
+
} = results[index];
|
|
195
|
+
|
|
196
|
+
if (isRequestable) {
|
|
197
|
+
const {
|
|
198
|
+
prefix
|
|
199
|
+
} = results[index];
|
|
200
|
+
const newUrl = prefix ? `${prefix}!${url}` : url;
|
|
201
|
+
const importKey = newUrl;
|
|
202
|
+
let importName = imports.get(importKey);
|
|
203
|
+
|
|
204
|
+
if (!importName) {
|
|
205
|
+
importName = `___CSS_LOADER_AT_RULE_IMPORT_${imports.size}___`;
|
|
206
|
+
imports.set(importKey, importName);
|
|
207
|
+
options.imports.push({
|
|
208
|
+
importName,
|
|
209
|
+
url: options.urlHandler(newUrl),
|
|
210
|
+
index
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
options.api.push({
|
|
215
|
+
importName,
|
|
216
|
+
media,
|
|
217
|
+
index
|
|
218
|
+
}); // eslint-disable-next-line no-continue
|
|
219
|
+
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
options.api.push({
|
|
224
|
+
url,
|
|
225
|
+
media,
|
|
226
|
+
index
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
};
|
|
232
|
+
}
|
|
210
233
|
|
|
211
|
-
|
|
212
|
-
}
|
|
234
|
+
};
|
|
235
|
+
};
|
|
213
236
|
|
|
237
|
+
plugin.postcss = true;
|
|
238
|
+
var _default = plugin;
|
|
214
239
|
exports.default = _default;
|