css-loader 4.3.0 → 5.0.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 +20 -0
- package/README.md +5 -3
- package/dist/CssSyntaxError.js +3 -1
- package/dist/index.js +10 -2
- package/dist/options.json +0 -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 +198 -194
- package/dist/runtime/api.js +3 -31
- package/dist/runtime/cssWithMappingToString.js +32 -0
- package/dist/utils.js +59 -27
- package/package.json +28 -28
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.0.0](https://github.com/webpack-contrib/css-loader/compare/v4.3.0...v5.0.0) (2020-10-13)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* migrate on PostCSS 8
|
|
11
|
+
* runtime doesn't contain source maps code without `sourceMap: true`
|
|
12
|
+
* returned value from the `getLocalIdent` escapes by default, the `exportName` value is always unescaped
|
|
13
|
+
* Auto enable icss modules for all files for which `/\.icss\.\w+$/i` (the `modules.compileType` option is `icss`)
|
|
14
|
+
* `[emoji]` placeholder was deprecated
|
|
15
|
+
* `icss` option was removed (it was deprecated previously)
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* allow named exports to have underscores in names ([#1209](https://github.com/webpack-contrib/css-loader/issues/1209)) ([747d62b](https://github.com/webpack-contrib/css-loader/commit/747d62b75a878d8881f4819b96297667dc689b8f))
|
|
20
|
+
* hide warning when you don't need handle `url()`/`@import` ([#1195](https://github.com/webpack-contrib/css-loader/issues/1195)) ([dd52931](https://github.com/webpack-contrib/css-loader/commit/dd52931150ed42f122d9017642437c26cc1b2422))
|
|
21
|
+
* improve error message ([52412f6](https://github.com/webpack-contrib/css-loader/commit/52412f6d5a54745ee37a4a67f038455c26ba5772))
|
|
22
|
+
* reduce runtime ([9f974be](https://github.com/webpack-contrib/css-loader/commit/9f974be81f5942d3afaf783529677bd541952fa3))
|
|
23
|
+
* add fallback if custom getLocalIdent returns `null`/`undefined` ([#1193](https://github.com/webpack-contrib/css-loader/issues/1193)) ([0f95841](https://github.com/webpack-contrib/css-loader/commit/0f9584135e63f9f354043e7f414e0c1aad0edc6e))
|
|
24
|
+
|
|
5
25
|
## [4.3.0](https://github.com/webpack-contrib/css-loader/compare/v4.2.2...v4.3.0) (2020-09-08)
|
|
6
26
|
|
|
7
27
|
|
package/README.md
CHANGED
|
@@ -530,7 +530,7 @@ module.exports = {
|
|
|
530
530
|
auto: true,
|
|
531
531
|
exportGlobals: true,
|
|
532
532
|
localIdentName: '[path][name]__[local]--[hash:base64:5]',
|
|
533
|
-
|
|
533
|
+
localIdentContext: path.resolve(__dirname, 'src'),
|
|
534
534
|
localIdentHashPrefix: 'my-custom-hash',
|
|
535
535
|
namedExport: true,
|
|
536
536
|
exportLocalsConvention: 'camelCase',
|
|
@@ -780,7 +780,7 @@ module.exports = {
|
|
|
780
780
|
loader: 'css-loader',
|
|
781
781
|
options: {
|
|
782
782
|
modules: {
|
|
783
|
-
|
|
783
|
+
localIdentContext: path.resolve(__dirname, 'src'),
|
|
784
784
|
},
|
|
785
785
|
},
|
|
786
786
|
},
|
|
@@ -848,6 +848,8 @@ Default: `undefined`
|
|
|
848
848
|
|
|
849
849
|
Allows to specify a function to generate the classname.
|
|
850
850
|
By default we use built-in function to generate a classname.
|
|
851
|
+
If the custom function returns `null` or `undefined`, we fallback to the
|
|
852
|
+
built-in function to generate the classname.
|
|
851
853
|
|
|
852
854
|
**webpack.config.js**
|
|
853
855
|
|
|
@@ -1245,7 +1247,7 @@ module.exports = {
|
|
|
1245
1247
|
|
|
1246
1248
|
### Separating `Interoperable CSS`-only and `CSS Module` features
|
|
1247
1249
|
|
|
1248
|
-
The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `compileType` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
|
|
1250
|
+
The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `compileType` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
|
|
1249
1251
|
Meanwhile all files matching `*.module.scss` are treated as `CSS Modules` in this example.
|
|
1250
1252
|
|
|
1251
1253
|
An example case is assumed where a project requires canvas drawing variables to be synchronized with CSS - canvas drawing uses the same color (set by color name in JavaScript) as HTML background (set by class name in CSS).
|
package/dist/CssSyntaxError.js
CHANGED
|
@@ -11,7 +11,8 @@ class CssSyntaxError extends Error {
|
|
|
11
11
|
const {
|
|
12
12
|
reason,
|
|
13
13
|
line,
|
|
14
|
-
column
|
|
14
|
+
column,
|
|
15
|
+
file
|
|
15
16
|
} = error;
|
|
16
17
|
this.name = 'CssSyntaxError'; // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
|
|
17
18
|
// We don't need `plugin` and `file` properties.
|
|
@@ -22,6 +23,7 @@ class CssSyntaxError extends Error {
|
|
|
22
23
|
this.message += `(${line}:${column}) `;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
this.message += file ? `${file} ` : '<css input> ';
|
|
25
27
|
this.message += `${reason}`;
|
|
26
28
|
const code = error.showSourceCode();
|
|
27
29
|
|
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,7 +33,7 @@ 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.
|
|
36
|
+
(0, _schemaUtils.validate)(_options.default, rawOptions, {
|
|
37
37
|
name: 'CSS Loader',
|
|
38
38
|
baseDataPath: 'options'
|
|
39
39
|
});
|
|
@@ -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 ? {
|
|
@@ -167,6 +168,13 @@ async function loader(content, map, meta) {
|
|
|
167
168
|
importName: '___CSS_LOADER_API_IMPORT___',
|
|
168
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"
|
|
@@ -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;
|