css-loader 4.2.2 → 5.0.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/CHANGELOG.md +46 -0
- package/README.md +120 -86
- 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 +3 -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 +199 -195
- 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 +126 -96
- package/package.json +37 -36
package/dist/cjs.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var _postcss = _interopRequireDefault(require("postcss"));
|
|
|
11
11
|
|
|
12
12
|
var _package = _interopRequireDefault(require("postcss/package.json"));
|
|
13
13
|
|
|
14
|
-
var _schemaUtils =
|
|
14
|
+
var _schemaUtils = require("schema-utils");
|
|
15
15
|
|
|
16
16
|
var _semver = require("semver");
|
|
17
17
|
|
|
@@ -33,9 +33,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
33
33
|
*/
|
|
34
34
|
async function loader(content, map, meta) {
|
|
35
35
|
const rawOptions = (0, _loaderUtils.getOptions)(this);
|
|
36
|
-
(0, _schemaUtils.
|
|
37
|
-
name:
|
|
38
|
-
baseDataPath:
|
|
36
|
+
(0, _schemaUtils.validate)(_options.default, rawOptions, {
|
|
37
|
+
name: "CSS Loader",
|
|
38
|
+
baseDataPath: "options"
|
|
39
39
|
});
|
|
40
40
|
const plugins = [];
|
|
41
41
|
const callback = this.async();
|
|
@@ -60,10 +60,10 @@ async function loader(content, map, meta) {
|
|
|
60
60
|
|
|
61
61
|
if ((0, _utils.shouldUseImportPlugin)(options)) {
|
|
62
62
|
const resolver = this.getResolve({
|
|
63
|
-
conditionNames: [
|
|
64
|
-
extensions: [
|
|
65
|
-
mainFields: [
|
|
66
|
-
mainFiles: [
|
|
63
|
+
conditionNames: ["style"],
|
|
64
|
+
extensions: [".css"],
|
|
65
|
+
mainFields: ["css", "style", "main", "..."],
|
|
66
|
+
mainFiles: ["index", "..."],
|
|
67
67
|
restrictions: [/\.css$/i]
|
|
68
68
|
});
|
|
69
69
|
plugins.push((0, _plugins.importParser)({
|
|
@@ -81,8 +81,8 @@ async function loader(content, map, meta) {
|
|
|
81
81
|
|
|
82
82
|
if ((0, _utils.shouldUseURLPlugin)(options)) {
|
|
83
83
|
const urlResolver = this.getResolve({
|
|
84
|
-
conditionNames: [
|
|
85
|
-
mainFields: [
|
|
84
|
+
conditionNames: ["asset"],
|
|
85
|
+
mainFields: ["asset"],
|
|
86
86
|
mainFiles: [],
|
|
87
87
|
extensions: []
|
|
88
88
|
});
|
|
@@ -102,10 +102,10 @@ async function loader(content, map, meta) {
|
|
|
102
102
|
|
|
103
103
|
if ((0, _utils.shouldUseIcssPlugin)(options)) {
|
|
104
104
|
const icssResolver = this.getResolve({
|
|
105
|
-
conditionNames: [
|
|
105
|
+
conditionNames: ["style"],
|
|
106
106
|
extensions: [],
|
|
107
|
-
mainFields: [
|
|
108
|
-
mainFiles: [
|
|
107
|
+
mainFields: ["css", "style", "main", "..."],
|
|
108
|
+
mainFiles: ["index", "..."]
|
|
109
109
|
});
|
|
110
110
|
plugins.push((0, _plugins.icssParser)({
|
|
111
111
|
imports: icssPluginImports,
|
|
@@ -125,7 +125,7 @@ async function loader(content, map, meta) {
|
|
|
125
125
|
ast
|
|
126
126
|
} = meta;
|
|
127
127
|
|
|
128
|
-
if (ast && ast.type ===
|
|
128
|
+
if (ast && ast.type === "postcss" && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
|
|
129
129
|
// eslint-disable-next-line no-param-reassign
|
|
130
130
|
content = ast.root;
|
|
131
131
|
}
|
|
@@ -138,6 +138,7 @@ async function loader(content, map, meta) {
|
|
|
138
138
|
|
|
139
139
|
try {
|
|
140
140
|
result = await (0, _postcss.default)(plugins).process(content, {
|
|
141
|
+
hideNothingWarning: true,
|
|
141
142
|
from: resourcePath,
|
|
142
143
|
to: resourcePath,
|
|
143
144
|
map: options.sourceMap ? {
|
|
@@ -151,7 +152,7 @@ async function loader(content, map, meta) {
|
|
|
151
152
|
this.addDependency(error.file);
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
callback(error.name ===
|
|
155
|
+
callback(error.name === "CssSyntaxError" ? new _CssSyntaxError.default(error) : error);
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
157
158
|
|
|
@@ -164,9 +165,16 @@ async function loader(content, map, meta) {
|
|
|
164
165
|
|
|
165
166
|
if (options.modules.exportOnlyLocals !== true) {
|
|
166
167
|
imports.unshift({
|
|
167
|
-
importName:
|
|
168
|
-
url: (0, _loaderUtils.stringifyRequest)(this, require.resolve(
|
|
168
|
+
importName: "___CSS_LOADER_API_IMPORT___",
|
|
169
|
+
url: (0, _loaderUtils.stringifyRequest)(this, require.resolve("./runtime/api"))
|
|
169
170
|
});
|
|
171
|
+
|
|
172
|
+
if (options.sourceMap) {
|
|
173
|
+
imports.unshift({
|
|
174
|
+
importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
|
|
175
|
+
url: (0, _loaderUtils.stringifyRequest)(this, require.resolve("./runtime/cssWithMappingToString"))
|
|
176
|
+
});
|
|
177
|
+
}
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
const importCode = (0, _utils.getImportCode)(imports, options);
|
package/dist/options.json
CHANGED
|
@@ -122,10 +122,6 @@
|
|
|
122
122
|
}
|
|
123
123
|
]
|
|
124
124
|
},
|
|
125
|
-
"icss": {
|
|
126
|
-
"description": "Enables/Disables handling the CSS module interoperable import/export format ((https://github.com/webpack-contrib/css-loader#icss)",
|
|
127
|
-
"type": "boolean"
|
|
128
|
-
},
|
|
129
125
|
"sourceMap": {
|
|
130
126
|
"description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
|
|
131
127
|
"type": "boolean"
|
|
@@ -136,6 +132,9 @@
|
|
|
136
132
|
{
|
|
137
133
|
"type": "boolean"
|
|
138
134
|
},
|
|
135
|
+
{
|
|
136
|
+
"type": "string"
|
|
137
|
+
},
|
|
139
138
|
{
|
|
140
139
|
"type": "integer"
|
|
141
140
|
}
|
|
@@ -5,109 +5,114 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
-
|
|
10
8
|
var _icssUtils = require("icss-utils");
|
|
11
9
|
|
|
12
10
|
var _utils = require("../utils");
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const importReplacements = Object.create(null);
|
|
18
|
-
const {
|
|
19
|
-
icssImports,
|
|
20
|
-
icssExports
|
|
21
|
-
} = (0, _icssUtils.extractICSS)(css);
|
|
22
|
-
const imports = new Map();
|
|
23
|
-
const tasks = []; // eslint-disable-next-line guard-for-in
|
|
24
|
-
|
|
25
|
-
for (const url in icssImports) {
|
|
26
|
-
const tokens = icssImports[url];
|
|
27
|
-
|
|
28
|
-
if (Object.keys(tokens).length === 0) {
|
|
29
|
-
// eslint-disable-next-line no-continue
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let normalizedUrl = url;
|
|
34
|
-
let prefix = '';
|
|
35
|
-
const queryParts = normalizedUrl.split('!');
|
|
12
|
+
const plugin = (options = {}) => {
|
|
13
|
+
return {
|
|
14
|
+
postcssPlugin: "postcss-icss-parser",
|
|
36
15
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
prefix = queryParts.join('!');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), options.rootContext);
|
|
43
|
-
|
|
44
|
-
const doResolve = async () => {
|
|
16
|
+
async OnceExit(root) {
|
|
17
|
+
const importReplacements = Object.create(null);
|
|
45
18
|
const {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} =
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
tokens
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
19
|
+
icssImports,
|
|
20
|
+
icssExports
|
|
21
|
+
} = (0, _icssUtils.extractICSS)(root);
|
|
22
|
+
const imports = new Map();
|
|
23
|
+
const tasks = []; // eslint-disable-next-line guard-for-in
|
|
24
|
+
|
|
25
|
+
for (const url in icssImports) {
|
|
26
|
+
const tokens = icssImports[url];
|
|
27
|
+
|
|
28
|
+
if (Object.keys(tokens).length === 0) {
|
|
29
|
+
// eslint-disable-next-line no-continue
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let normalizedUrl = url;
|
|
34
|
+
let prefix = "";
|
|
35
|
+
const queryParts = normalizedUrl.split("!");
|
|
36
|
+
|
|
37
|
+
if (queryParts.length > 1) {
|
|
38
|
+
normalizedUrl = queryParts.pop();
|
|
39
|
+
prefix = queryParts.join("!");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), options.rootContext);
|
|
43
|
+
|
|
44
|
+
const doResolve = async () => {
|
|
45
|
+
const {
|
|
46
|
+
resolver,
|
|
47
|
+
context
|
|
48
|
+
} = options;
|
|
49
|
+
const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([normalizedUrl, request])]);
|
|
50
|
+
return {
|
|
51
|
+
url: resolvedUrl,
|
|
52
|
+
prefix,
|
|
53
|
+
tokens
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
tasks.push(doResolve());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const results = await Promise.all(tasks);
|
|
61
|
+
|
|
62
|
+
for (let index = 0; index <= results.length - 1; index++) {
|
|
63
|
+
const {
|
|
64
|
+
url,
|
|
65
|
+
prefix,
|
|
66
|
+
tokens
|
|
67
|
+
} = results[index];
|
|
68
|
+
const newUrl = prefix ? `${prefix}!${url}` : url;
|
|
69
|
+
const importKey = newUrl;
|
|
70
|
+
let importName = imports.get(importKey);
|
|
71
|
+
|
|
72
|
+
if (!importName) {
|
|
73
|
+
importName = `___CSS_LOADER_ICSS_IMPORT_${imports.size}___`;
|
|
74
|
+
imports.set(importKey, importName);
|
|
75
|
+
options.imports.push({
|
|
76
|
+
importName,
|
|
77
|
+
url: options.urlHandler(newUrl),
|
|
78
|
+
icss: true,
|
|
79
|
+
index
|
|
80
|
+
});
|
|
81
|
+
options.api.push({
|
|
82
|
+
importName,
|
|
83
|
+
dedupe: true,
|
|
84
|
+
index
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const [replacementIndex, token] of Object.keys(tokens).entries()) {
|
|
89
|
+
const replacementName = `___CSS_LOADER_ICSS_IMPORT_${index}_REPLACEMENT_${replacementIndex}___`;
|
|
90
|
+
const localName = tokens[token];
|
|
91
|
+
importReplacements[token] = replacementName;
|
|
92
|
+
options.replacements.push({
|
|
93
|
+
replacementName,
|
|
94
|
+
importName,
|
|
95
|
+
localName
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (Object.keys(importReplacements).length > 0) {
|
|
101
|
+
(0, _icssUtils.replaceSymbols)(root, importReplacements);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (const name of Object.keys(icssExports)) {
|
|
105
|
+
const value = (0, _icssUtils.replaceValueSymbols)(icssExports[name], importReplacements);
|
|
106
|
+
options.exports.push({
|
|
107
|
+
name,
|
|
108
|
+
value
|
|
109
|
+
});
|
|
110
|
+
}
|
|
86
111
|
}
|
|
87
112
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const localName = tokens[token];
|
|
91
|
-
importReplacements[token] = replacementName;
|
|
92
|
-
options.replacements.push({
|
|
93
|
-
replacementName,
|
|
94
|
-
importName,
|
|
95
|
-
localName
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (Object.keys(importReplacements).length > 0) {
|
|
101
|
-
(0, _icssUtils.replaceSymbols)(css, importReplacements);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
for (const name of Object.keys(icssExports)) {
|
|
105
|
-
const value = (0, _icssUtils.replaceValueSymbols)(icssExports[name], importReplacements);
|
|
106
|
-
options.exports.push({
|
|
107
|
-
name,
|
|
108
|
-
value
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
});
|
|
113
|
+
};
|
|
114
|
+
};
|
|
112
115
|
|
|
116
|
+
plugin.postcss = true;
|
|
117
|
+
var _default = plugin;
|
|
113
118
|
exports.default = _default;
|