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
package/dist/index.js
CHANGED
|
@@ -5,14 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = loader;
|
|
7
7
|
|
|
8
|
-
var _loaderUtils = require("loader-utils");
|
|
9
|
-
|
|
10
8
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
11
9
|
|
|
12
10
|
var _package = _interopRequireDefault(require("postcss/package.json"));
|
|
13
11
|
|
|
14
|
-
var _schemaUtils = require("schema-utils");
|
|
15
|
-
|
|
16
12
|
var _semver = require("semver");
|
|
17
13
|
|
|
18
14
|
var _CssSyntaxError = _interopRequireDefault(require("./CssSyntaxError"));
|
|
@@ -32,11 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
32
28
|
Author Tobias Koppers @sokra
|
|
33
29
|
*/
|
|
34
30
|
async function loader(content, map, meta) {
|
|
35
|
-
const rawOptions =
|
|
36
|
-
(0, _schemaUtils.validate)(_options.default, rawOptions, {
|
|
37
|
-
name: "CSS Loader",
|
|
38
|
-
baseDataPath: "options"
|
|
39
|
-
});
|
|
31
|
+
const rawOptions = this.getOptions(_options.default);
|
|
40
32
|
const plugins = [];
|
|
41
33
|
const callback = this.async();
|
|
42
34
|
let options;
|
|
@@ -59,40 +51,36 @@ async function loader(content, map, meta) {
|
|
|
59
51
|
const importPluginApi = [];
|
|
60
52
|
|
|
61
53
|
if ((0, _utils.shouldUseImportPlugin)(options)) {
|
|
62
|
-
const resolver = this.getResolve({
|
|
63
|
-
conditionNames: ["style"],
|
|
64
|
-
extensions: [".css"],
|
|
65
|
-
mainFields: ["css", "style", "main", "..."],
|
|
66
|
-
mainFiles: ["index", "..."]
|
|
67
|
-
});
|
|
68
54
|
plugins.push((0, _plugins.importParser)({
|
|
55
|
+
isCSSStyleSheet: options.exportType === "css-style-sheet",
|
|
56
|
+
loaderContext: this,
|
|
69
57
|
imports: importPluginImports,
|
|
70
58
|
api: importPluginApi,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
filter: (0, _utils.getFilter)(options.import, this.resourcePath),
|
|
74
|
-
resolver,
|
|
75
|
-
urlHandler: url => (0, _loaderUtils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
|
|
59
|
+
filter: options.import.filter,
|
|
60
|
+
urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
|
|
76
61
|
}));
|
|
77
62
|
}
|
|
78
63
|
|
|
79
64
|
const urlPluginImports = [];
|
|
80
65
|
|
|
81
66
|
if ((0, _utils.shouldUseURLPlugin)(options)) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
mainFields: ["asset"],
|
|
85
|
-
mainFiles: [],
|
|
86
|
-
extensions: []
|
|
87
|
-
});
|
|
67
|
+
const needToResolveURL = !options.esModule;
|
|
68
|
+
const isSupportDataURLInNewURL = options.esModule && Boolean("fsStartTime" in this._compiler);
|
|
88
69
|
plugins.push((0, _plugins.urlParser)({
|
|
89
70
|
imports: urlPluginImports,
|
|
90
71
|
replacements,
|
|
91
72
|
context: this.context,
|
|
92
73
|
rootContext: this.rootContext,
|
|
93
|
-
filter: (0, _utils.getFilter)(options.url, this.resourcePath),
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
filter: (0, _utils.getFilter)(options.url.filter, this.resourcePath),
|
|
75
|
+
needToResolveURL,
|
|
76
|
+
resolver: needToResolveURL ? this.getResolve({
|
|
77
|
+
mainFiles: [],
|
|
78
|
+
extensions: []
|
|
79
|
+
}) : // eslint-disable-next-line no-undefined
|
|
80
|
+
undefined,
|
|
81
|
+
urlHandler: url => (0, _utils.stringifyRequest)(this, url),
|
|
82
|
+
// Support data urls as input in new URL added in webpack@5.38.0
|
|
83
|
+
isSupportDataURLInNewURL
|
|
96
84
|
}));
|
|
97
85
|
}
|
|
98
86
|
|
|
@@ -101,21 +89,13 @@ async function loader(content, map, meta) {
|
|
|
101
89
|
const needToUseIcssPlugin = (0, _utils.shouldUseIcssPlugin)(options);
|
|
102
90
|
|
|
103
91
|
if (needToUseIcssPlugin) {
|
|
104
|
-
const icssResolver = this.getResolve({
|
|
105
|
-
conditionNames: ["style"],
|
|
106
|
-
extensions: [],
|
|
107
|
-
mainFields: ["css", "style", "main", "..."],
|
|
108
|
-
mainFiles: ["index", "..."]
|
|
109
|
-
});
|
|
110
92
|
plugins.push((0, _plugins.icssParser)({
|
|
93
|
+
loaderContext: this,
|
|
111
94
|
imports: icssPluginImports,
|
|
112
95
|
api: icssPluginApi,
|
|
113
96
|
replacements,
|
|
114
97
|
exports,
|
|
115
|
-
|
|
116
|
-
rootContext: this.rootContext,
|
|
117
|
-
resolver: icssResolver,
|
|
118
|
-
urlHandler: url => (0, _loaderUtils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
|
|
98
|
+
urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
|
|
119
99
|
}));
|
|
120
100
|
} // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
|
|
121
101
|
|
|
@@ -165,20 +145,34 @@ async function loader(content, map, meta) {
|
|
|
165
145
|
|
|
166
146
|
if (options.modules.exportOnlyLocals !== true) {
|
|
167
147
|
imports.unshift({
|
|
148
|
+
type: "api_import",
|
|
168
149
|
importName: "___CSS_LOADER_API_IMPORT___",
|
|
169
|
-
url: (0,
|
|
150
|
+
url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/api"))
|
|
170
151
|
});
|
|
171
152
|
|
|
172
153
|
if (options.sourceMap) {
|
|
173
154
|
imports.unshift({
|
|
174
155
|
importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
|
|
175
|
-
url: (0,
|
|
156
|
+
url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/sourceMaps"))
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
imports.unshift({
|
|
160
|
+
importName: "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___",
|
|
161
|
+
url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/noSourceMaps"))
|
|
176
162
|
});
|
|
177
163
|
}
|
|
178
164
|
}
|
|
179
165
|
|
|
180
166
|
const importCode = (0, _utils.getImportCode)(imports, options);
|
|
181
|
-
|
|
167
|
+
let moduleCode;
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
callback(error);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
182
176
|
const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options);
|
|
183
177
|
callback(null, `${importCode}${moduleCode}${exportCode}`);
|
|
184
178
|
}
|
package/dist/options.json
CHANGED
|
@@ -1,47 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
+
"title": "CSS Loader options",
|
|
2
3
|
"additionalProperties": false,
|
|
3
4
|
"properties": {
|
|
4
5
|
"url": {
|
|
5
|
-
"description": "
|
|
6
|
+
"description": "Allows to enables/disables `url()`/`image-set()` functions handling.",
|
|
7
|
+
"link": "https://github.com/webpack-contrib/css-loader#url",
|
|
6
8
|
"anyOf": [
|
|
7
9
|
{
|
|
8
10
|
"type": "boolean"
|
|
9
11
|
},
|
|
10
12
|
{
|
|
11
|
-
"
|
|
13
|
+
"type": "object",
|
|
14
|
+
"properties": {
|
|
15
|
+
"filter": {
|
|
16
|
+
"instanceof": "Function"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"additionalProperties": false
|
|
12
20
|
}
|
|
13
21
|
]
|
|
14
22
|
},
|
|
15
23
|
"import": {
|
|
16
|
-
"description": "
|
|
24
|
+
"description": "Allows to enables/disables `@import` at-rules handling.",
|
|
25
|
+
"link": "https://github.com/webpack-contrib/css-loader#import",
|
|
17
26
|
"anyOf": [
|
|
18
27
|
{
|
|
19
28
|
"type": "boolean"
|
|
20
29
|
},
|
|
21
30
|
{
|
|
22
|
-
"
|
|
31
|
+
"type": "object",
|
|
32
|
+
"properties": {
|
|
33
|
+
"filter": {
|
|
34
|
+
"instanceof": "Function"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"additionalProperties": false
|
|
23
38
|
}
|
|
24
39
|
]
|
|
25
40
|
},
|
|
26
41
|
"modules": {
|
|
27
|
-
"description": "
|
|
42
|
+
"description": "Allows to enable/disable CSS Modules or ICSS and setup configuration.",
|
|
43
|
+
"link": "https://github.com/webpack-contrib/css-loader#modules",
|
|
28
44
|
"anyOf": [
|
|
29
45
|
{
|
|
30
46
|
"type": "boolean"
|
|
31
47
|
},
|
|
32
48
|
{
|
|
33
|
-
"enum": ["local", "global", "pure"]
|
|
49
|
+
"enum": ["local", "global", "pure", "icss"]
|
|
34
50
|
},
|
|
35
51
|
{
|
|
36
52
|
"type": "object",
|
|
37
53
|
"additionalProperties": false,
|
|
38
54
|
"properties": {
|
|
39
|
-
"compileType": {
|
|
40
|
-
"description": "Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)",
|
|
41
|
-
"enum": ["module", "icss"]
|
|
42
|
-
},
|
|
43
55
|
"auto": {
|
|
44
|
-
"description": "Allows auto enable CSS modules based on filename
|
|
56
|
+
"description": "Allows auto enable CSS modules based on filename.",
|
|
57
|
+
"link": "https://github.com/webpack-contrib/css-loader#auto",
|
|
45
58
|
"anyOf": [
|
|
46
59
|
{
|
|
47
60
|
"instanceof": "RegExp"
|
|
@@ -55,10 +68,11 @@
|
|
|
55
68
|
]
|
|
56
69
|
},
|
|
57
70
|
"mode": {
|
|
58
|
-
"description": "Setup `mode` option
|
|
71
|
+
"description": "Setup `mode` option.",
|
|
72
|
+
"link": "https://github.com/webpack-contrib/css-loader#mode",
|
|
59
73
|
"anyOf": [
|
|
60
74
|
{
|
|
61
|
-
"enum": ["local", "global", "pure"]
|
|
75
|
+
"enum": ["local", "global", "pure", "icss"]
|
|
62
76
|
},
|
|
63
77
|
{
|
|
64
78
|
"instanceof": "Function"
|
|
@@ -66,22 +80,43 @@
|
|
|
66
80
|
]
|
|
67
81
|
},
|
|
68
82
|
"localIdentName": {
|
|
69
|
-
"description": "Allows to configure the generated local ident name
|
|
83
|
+
"description": "Allows to configure the generated local ident name.",
|
|
84
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidentname",
|
|
70
85
|
"type": "string",
|
|
71
86
|
"minLength": 1
|
|
72
87
|
},
|
|
73
88
|
"localIdentContext": {
|
|
74
|
-
"description": "Allows to redefine basic loader context for local ident name
|
|
89
|
+
"description": "Allows to redefine basic loader context for local ident name.",
|
|
90
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidentcontext",
|
|
91
|
+
"type": "string",
|
|
92
|
+
"minLength": 1
|
|
93
|
+
},
|
|
94
|
+
"localIdentHashSalt": {
|
|
95
|
+
"description": "Allows to add custom hash to generate more unique classes.",
|
|
96
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidenthashsalt",
|
|
75
97
|
"type": "string",
|
|
76
98
|
"minLength": 1
|
|
77
99
|
},
|
|
78
|
-
"
|
|
79
|
-
"description": "Allows to
|
|
100
|
+
"localIdentHashFunction": {
|
|
101
|
+
"description": "Allows to specify hash function to generate classes.",
|
|
102
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidenthashfunction",
|
|
80
103
|
"type": "string",
|
|
81
104
|
"minLength": 1
|
|
82
105
|
},
|
|
106
|
+
"localIdentHashDigest": {
|
|
107
|
+
"description": "Allows to specify hash digest to generate classes.",
|
|
108
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidenthashdigest",
|
|
109
|
+
"type": "string",
|
|
110
|
+
"minLength": 1
|
|
111
|
+
},
|
|
112
|
+
"localIdentHashDigestLength": {
|
|
113
|
+
"description": "Allows to specify hash digest length to generate classes.",
|
|
114
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidenthashdigestlength",
|
|
115
|
+
"type": "number"
|
|
116
|
+
},
|
|
83
117
|
"localIdentRegExp": {
|
|
84
|
-
"description": "Allows to specify custom RegExp for local ident name
|
|
118
|
+
"description": "Allows to specify custom RegExp for local ident name.",
|
|
119
|
+
"link": "https://github.com/webpack-contrib/css-loader#localidentregexp",
|
|
85
120
|
"anyOf": [
|
|
86
121
|
{
|
|
87
122
|
"type": "string",
|
|
@@ -93,29 +128,41 @@
|
|
|
93
128
|
]
|
|
94
129
|
},
|
|
95
130
|
"getLocalIdent": {
|
|
96
|
-
"description": "Allows to specify a function to generate the classname
|
|
131
|
+
"description": "Allows to specify a function to generate the classname.",
|
|
132
|
+
"link": "https://github.com/webpack-contrib/css-loader#getlocalident",
|
|
97
133
|
"instanceof": "Function"
|
|
98
134
|
},
|
|
99
135
|
"namedExport": {
|
|
100
|
-
"description": "Enables/disables ES modules named export for locals
|
|
136
|
+
"description": "Enables/disables ES modules named export for locals.",
|
|
137
|
+
"link": "https://github.com/webpack-contrib/css-loader#namedexport",
|
|
101
138
|
"type": "boolean"
|
|
102
139
|
},
|
|
103
140
|
"exportGlobals": {
|
|
104
|
-
"description": "Allows to export names from global class or id, so you can use that as local name
|
|
141
|
+
"description": "Allows to export names from global class or id, so you can use that as local name.",
|
|
142
|
+
"link": "https://github.com/webpack-contrib/css-loader#exportglobals",
|
|
105
143
|
"type": "boolean"
|
|
106
144
|
},
|
|
107
145
|
"exportLocalsConvention": {
|
|
108
|
-
"description": "Style of exported classnames
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
146
|
+
"description": "Style of exported classnames.",
|
|
147
|
+
"link": "https://github.com/webpack-contrib/css-loader#localsconvention",
|
|
148
|
+
"anyOf": [
|
|
149
|
+
{
|
|
150
|
+
"enum": [
|
|
151
|
+
"asIs",
|
|
152
|
+
"camelCase",
|
|
153
|
+
"camelCaseOnly",
|
|
154
|
+
"dashes",
|
|
155
|
+
"dashesOnly"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"instanceof": "Function"
|
|
160
|
+
}
|
|
115
161
|
]
|
|
116
162
|
},
|
|
117
163
|
"exportOnlyLocals": {
|
|
118
|
-
"description": "Export only locals
|
|
164
|
+
"description": "Export only locals.",
|
|
165
|
+
"link": "https://github.com/webpack-contrib/css-loader#exportonlylocals",
|
|
119
166
|
"type": "boolean"
|
|
120
167
|
}
|
|
121
168
|
}
|
|
@@ -123,11 +170,13 @@
|
|
|
123
170
|
]
|
|
124
171
|
},
|
|
125
172
|
"sourceMap": {
|
|
126
|
-
"description": "
|
|
173
|
+
"description": "Allows to enable/disable source maps.",
|
|
174
|
+
"link": "https://github.com/webpack-contrib/css-loader#sourcemap",
|
|
127
175
|
"type": "boolean"
|
|
128
176
|
},
|
|
129
177
|
"importLoaders": {
|
|
130
|
-
"description": "
|
|
178
|
+
"description": "Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports.",
|
|
179
|
+
"link": "https://github.com/webpack-contrib/css-loader#importloaders",
|
|
131
180
|
"anyOf": [
|
|
132
181
|
{
|
|
133
182
|
"type": "boolean"
|
|
@@ -141,8 +190,14 @@
|
|
|
141
190
|
]
|
|
142
191
|
},
|
|
143
192
|
"esModule": {
|
|
144
|
-
"description": "Use the ES modules syntax
|
|
193
|
+
"description": "Use the ES modules syntax.",
|
|
194
|
+
"link": "https://github.com/webpack-contrib/css-loader#esmodule",
|
|
145
195
|
"type": "boolean"
|
|
196
|
+
},
|
|
197
|
+
"exportType": {
|
|
198
|
+
"description": "Allows exporting styles as array with modules, string or constructable stylesheet (i.e. `CSSStyleSheet`).",
|
|
199
|
+
"link": "https://github.com/webpack-contrib/css-loader#exporttype",
|
|
200
|
+
"enum": ["array", "string", "css-style-sheet"]
|
|
146
201
|
}
|
|
147
202
|
},
|
|
148
203
|
"type": "object"
|
|
@@ -20,7 +20,18 @@ const plugin = (options = {}) => {
|
|
|
20
20
|
icssExports
|
|
21
21
|
} = (0, _icssUtils.extractICSS)(root);
|
|
22
22
|
const imports = new Map();
|
|
23
|
-
const tasks = [];
|
|
23
|
+
const tasks = [];
|
|
24
|
+
const {
|
|
25
|
+
loaderContext
|
|
26
|
+
} = options;
|
|
27
|
+
const resolver = loaderContext.getResolve({
|
|
28
|
+
dependencyType: "icss",
|
|
29
|
+
conditionNames: ["style"],
|
|
30
|
+
extensions: ["..."],
|
|
31
|
+
mainFields: ["css", "style", "main", "..."],
|
|
32
|
+
mainFiles: ["index", "..."],
|
|
33
|
+
preferRelative: true
|
|
34
|
+
}); // eslint-disable-next-line guard-for-in
|
|
24
35
|
|
|
25
36
|
for (const url in icssImports) {
|
|
26
37
|
const tokens = icssImports[url];
|
|
@@ -39,14 +50,10 @@ const plugin = (options = {}) => {
|
|
|
39
50
|
prefix = queryParts.join("!");
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true),
|
|
53
|
+
const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), loaderContext.rootContext);
|
|
43
54
|
|
|
44
55
|
const doResolve = async () => {
|
|
45
|
-
const
|
|
46
|
-
resolver,
|
|
47
|
-
context
|
|
48
|
-
} = options;
|
|
49
|
-
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([normalizedUrl, request])]);
|
|
56
|
+
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, loaderContext.context, [...new Set([normalizedUrl, request])]);
|
|
50
57
|
|
|
51
58
|
if (!resolvedUrl) {
|
|
52
59
|
return;
|
|
@@ -81,6 +88,7 @@ const plugin = (options = {}) => {
|
|
|
81
88
|
importName = `___CSS_LOADER_ICSS_IMPORT_${imports.size}___`;
|
|
82
89
|
imports.set(importKey, importName);
|
|
83
90
|
options.imports.push({
|
|
91
|
+
type: "icss_import",
|
|
84
92
|
importName,
|
|
85
93
|
url: options.urlHandler(newUrl),
|
|
86
94
|
icss: true,
|
|
@@ -43,9 +43,10 @@ function parseNode(atRule, key) {
|
|
|
43
43
|
throw error;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const rawParams = atRule.raws && atRule.raws[key] && typeof atRule.raws[key].raw !== "undefined" ? atRule.raws[key].raw : atRule[key];
|
|
46
47
|
const {
|
|
47
48
|
nodes: paramsNodes
|
|
48
|
-
} = (0, _postcssValueParser.default)(
|
|
49
|
+
} = (0, _postcssValueParser.default)(rawParams); // No nodes - `@import ;`
|
|
49
50
|
// Invalid type - `@import foo-bar;`
|
|
50
51
|
|
|
51
52
|
if (paramsNodes.length === 0 || paramsNodes[0].type !== "string" && paramsNodes[0].type !== "function") {
|
|
@@ -92,11 +93,42 @@ function parseNode(atRule, key) {
|
|
|
92
93
|
throw error;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
const
|
|
96
|
+
const additionalNodes = paramsNodes.slice(1);
|
|
97
|
+
let supports;
|
|
98
|
+
let layer;
|
|
96
99
|
let media;
|
|
97
100
|
|
|
98
|
-
if (
|
|
99
|
-
|
|
101
|
+
if (additionalNodes.length > 0) {
|
|
102
|
+
let nodes = [];
|
|
103
|
+
|
|
104
|
+
for (const node of additionalNodes) {
|
|
105
|
+
nodes.push(node);
|
|
106
|
+
const isLayerFunction = node.type === "function" && node.value.toLowerCase() === "layer";
|
|
107
|
+
const isLayerWord = node.type === "word" && node.value.toLowerCase() === "layer";
|
|
108
|
+
|
|
109
|
+
if (isLayerFunction || isLayerWord) {
|
|
110
|
+
if (isLayerFunction) {
|
|
111
|
+
nodes.splice(nodes.length - 1, 1, ...node.nodes);
|
|
112
|
+
} else {
|
|
113
|
+
nodes.splice(nodes.length - 1, 1, {
|
|
114
|
+
type: "string",
|
|
115
|
+
value: "",
|
|
116
|
+
unclosed: false
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
layer = _postcssValueParser.default.stringify(nodes).trim().toLowerCase();
|
|
121
|
+
nodes = [];
|
|
122
|
+
} else if (node.type === "function" && node.value.toLowerCase() === "supports") {
|
|
123
|
+
nodes.splice(nodes.length - 1, 1, ...node.nodes);
|
|
124
|
+
supports = _postcssValueParser.default.stringify(nodes).trim().toLowerCase();
|
|
125
|
+
nodes = [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (nodes.length > 0) {
|
|
130
|
+
media = _postcssValueParser.default.stringify(nodes).trim().toLowerCase();
|
|
131
|
+
}
|
|
100
132
|
} // eslint-disable-next-line consistent-return
|
|
101
133
|
|
|
102
134
|
|
|
@@ -104,6 +136,8 @@ function parseNode(atRule, key) {
|
|
|
104
136
|
atRule,
|
|
105
137
|
prefix,
|
|
106
138
|
url,
|
|
139
|
+
layer,
|
|
140
|
+
supports,
|
|
107
141
|
media,
|
|
108
142
|
isRequestable
|
|
109
143
|
};
|
|
@@ -118,6 +152,11 @@ const plugin = (options = {}) => {
|
|
|
118
152
|
return {
|
|
119
153
|
AtRule: {
|
|
120
154
|
import(atRule) {
|
|
155
|
+
if (options.isCSSStyleSheet) {
|
|
156
|
+
options.loaderContext.emitError(new Error(atRule.error("'@import' rules are not allowed here and will not be processed").message));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
121
160
|
let parsedAtRule;
|
|
122
161
|
|
|
123
162
|
try {
|
|
@@ -142,17 +181,30 @@ const plugin = (options = {}) => {
|
|
|
142
181
|
return;
|
|
143
182
|
}
|
|
144
183
|
|
|
184
|
+
const {
|
|
185
|
+
loaderContext
|
|
186
|
+
} = options;
|
|
187
|
+
const resolver = loaderContext.getResolve({
|
|
188
|
+
dependencyType: "css",
|
|
189
|
+
conditionNames: ["style"],
|
|
190
|
+
mainFields: ["css", "style", "main", "..."],
|
|
191
|
+
mainFiles: ["index", "..."],
|
|
192
|
+
extensions: [".css", "..."],
|
|
193
|
+
preferRelative: true
|
|
194
|
+
});
|
|
145
195
|
const resolvedAtRules = await Promise.all(parsedAtRules.map(async parsedAtRule => {
|
|
146
196
|
const {
|
|
147
197
|
atRule,
|
|
148
198
|
isRequestable,
|
|
149
199
|
prefix,
|
|
150
200
|
url,
|
|
201
|
+
layer,
|
|
202
|
+
supports,
|
|
151
203
|
media
|
|
152
204
|
} = parsedAtRule;
|
|
153
205
|
|
|
154
206
|
if (options.filter) {
|
|
155
|
-
const needKeep = await options.filter(url, media);
|
|
207
|
+
const needKeep = await options.filter(url, media, loaderContext.resourcePath, supports, layer);
|
|
156
208
|
|
|
157
209
|
if (!needKeep) {
|
|
158
210
|
return;
|
|
@@ -160,21 +212,24 @@ const plugin = (options = {}) => {
|
|
|
160
212
|
}
|
|
161
213
|
|
|
162
214
|
if (isRequestable) {
|
|
163
|
-
const request = (0, _utils.requestify)(url,
|
|
164
|
-
const
|
|
165
|
-
resolver,
|
|
166
|
-
context
|
|
167
|
-
} = options;
|
|
168
|
-
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, url])]);
|
|
215
|
+
const request = (0, _utils.requestify)(url, loaderContext.rootContext);
|
|
216
|
+
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, loaderContext.context, [...new Set([request, url])]);
|
|
169
217
|
|
|
170
218
|
if (!resolvedUrl) {
|
|
171
219
|
return;
|
|
172
220
|
}
|
|
173
221
|
|
|
222
|
+
if (resolvedUrl === loaderContext.resourcePath) {
|
|
223
|
+
atRule.remove();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
174
227
|
atRule.remove(); // eslint-disable-next-line consistent-return
|
|
175
228
|
|
|
176
229
|
return {
|
|
177
230
|
url: resolvedUrl,
|
|
231
|
+
layer,
|
|
232
|
+
supports,
|
|
178
233
|
media,
|
|
179
234
|
prefix,
|
|
180
235
|
isRequestable
|
|
@@ -185,6 +240,8 @@ const plugin = (options = {}) => {
|
|
|
185
240
|
|
|
186
241
|
return {
|
|
187
242
|
url,
|
|
243
|
+
layer,
|
|
244
|
+
supports,
|
|
188
245
|
media,
|
|
189
246
|
prefix,
|
|
190
247
|
isRequestable
|
|
@@ -203,12 +260,16 @@ const plugin = (options = {}) => {
|
|
|
203
260
|
const {
|
|
204
261
|
url,
|
|
205
262
|
isRequestable,
|
|
263
|
+
layer,
|
|
264
|
+
supports,
|
|
206
265
|
media
|
|
207
266
|
} = resolvedAtRule;
|
|
208
267
|
|
|
209
268
|
if (!isRequestable) {
|
|
210
269
|
options.api.push({
|
|
211
270
|
url,
|
|
271
|
+
layer,
|
|
272
|
+
supports,
|
|
212
273
|
media,
|
|
213
274
|
index
|
|
214
275
|
}); // eslint-disable-next-line no-continue
|
|
@@ -226,6 +287,7 @@ const plugin = (options = {}) => {
|
|
|
226
287
|
importName = `___CSS_LOADER_AT_RULE_IMPORT_${urlToNameMap.size}___`;
|
|
227
288
|
urlToNameMap.set(newUrl, importName);
|
|
228
289
|
options.imports.push({
|
|
290
|
+
type: "rule_import",
|
|
229
291
|
importName,
|
|
230
292
|
url: options.urlHandler(newUrl),
|
|
231
293
|
index
|
|
@@ -234,6 +296,8 @@ const plugin = (options = {}) => {
|
|
|
234
296
|
|
|
235
297
|
options.api.push({
|
|
236
298
|
importName,
|
|
299
|
+
layer,
|
|
300
|
+
supports,
|
|
237
301
|
media,
|
|
238
302
|
index
|
|
239
303
|
});
|