css-loader 5.0.2 → 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 +7 -0
- package/README.md +57 -3
- package/dist/plugins/postcss-import-parser.js +19 -0
- package/dist/plugins/postcss-url-parser.js +91 -3
- package/dist/utils.js +3 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.1.0](https://github.com/webpack-contrib/css-loader/compare/v5.0.2...v5.1.0) (2021-02-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added support webpackIgnore comment ([#1264](https://github.com/webpack-contrib/css-loader/issues/1264)) ([53d40a9](https://github.com/webpack-contrib/css-loader/commit/53d40a9bb35a79e6a15308bbb7a01358f39816df))
|
|
11
|
+
|
|
5
12
|
### [5.0.2](https://github.com/webpack-contrib/css-loader/compare/v5.0.1...v5.0.2) (2021-02-08)
|
|
6
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ Type: `Boolean|Function`
|
|
|
126
126
|
Default: `true`
|
|
127
127
|
|
|
128
128
|
Enables/Disables `url`/`image-set` functions handling.
|
|
129
|
-
Control `url()` resolving. Absolute URLs
|
|
129
|
+
Control `url()` resolving. Absolute paths and root-relative URLs now resolving(Version [4.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#400-2020-07-25) and above).
|
|
130
130
|
|
|
131
131
|
Examples resolutions:
|
|
132
132
|
|
|
@@ -588,8 +588,8 @@ Allows auto enable CSS modules based on filename.
|
|
|
588
588
|
|
|
589
589
|
Possible values:
|
|
590
590
|
|
|
591
|
-
- `true` -
|
|
592
|
-
- `false` -
|
|
591
|
+
- `true` - enables CSS modules or interoperable CSS format, sets the [`modules.compileType`](#compiletype) option to `module` value for all files which satisfy `/\.module(s)?\.\w+$/i.test(filename)` condition or sets the [`modules.compileType`](#compiletype) option to `icss` value for all files which satisfy `/\.icss\.\w+$/i.test(filename)` condition
|
|
592
|
+
- `false` - disables CSS modules or interoperable CSS format based on filename
|
|
593
593
|
|
|
594
594
|
**webpack.config.js**
|
|
595
595
|
|
|
@@ -1132,6 +1132,60 @@ module.exports = {
|
|
|
1132
1132
|
|
|
1133
1133
|
## Examples
|
|
1134
1134
|
|
|
1135
|
+
### Disable url resolving using the `/* webpackIgnore: true */` comment
|
|
1136
|
+
|
|
1137
|
+
With the help of the `/* webpackIgnore: true */`comment, it is possible to disable sources handling for rules and for individual declarations.
|
|
1138
|
+
|
|
1139
|
+
```css
|
|
1140
|
+
/* webpackIgnore: true */
|
|
1141
|
+
@import url(./basic.css);
|
|
1142
|
+
@import /* webpackIgnore: true */ url(./imported.css);
|
|
1143
|
+
|
|
1144
|
+
.class {
|
|
1145
|
+
/* Disabled url handling for the all urls in the 'background' declaration */
|
|
1146
|
+
color: red;
|
|
1147
|
+
/* webpackIgnore: true */
|
|
1148
|
+
background: url("./url/img.png"), url("./url/img.png");
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
.class {
|
|
1152
|
+
/* Disabled url handling for the first url in the 'background' declaration */
|
|
1153
|
+
color: red;
|
|
1154
|
+
background:
|
|
1155
|
+
/* webpackIgnore: true */ url("./url/img.png"), url("./url/img.png");
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
.class {
|
|
1159
|
+
/* Disabled url handling for the second url in the 'background' declaration */
|
|
1160
|
+
color: red;
|
|
1161
|
+
background: url("./url/img.png"),
|
|
1162
|
+
/* webpackIgnore: true */ url("./url/img.png");
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/* prettier-ignore */
|
|
1166
|
+
.class {
|
|
1167
|
+
/* Disabled url handling for the second url in the 'background' declaration */
|
|
1168
|
+
color: red;
|
|
1169
|
+
background: url("./url/img.png"),
|
|
1170
|
+
/* webpackIgnore: true */
|
|
1171
|
+
url("./url/img.png");
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/* prettier-ignore */
|
|
1175
|
+
.class {
|
|
1176
|
+
/* Disabled url handling for third and sixth urls in the 'background-image' declaration */
|
|
1177
|
+
background-image: image-set(
|
|
1178
|
+
url(./url/img.png) 2x,
|
|
1179
|
+
url(./url/img.png) 3x,
|
|
1180
|
+
/* webpackIgnore: true */ url(./url/img.png) 4x,
|
|
1181
|
+
url(./url/img.png) 5x,
|
|
1182
|
+
url(./url/img.png) 6x,
|
|
1183
|
+
/* webpackIgnore: true */
|
|
1184
|
+
url(./url/img.png) 7x
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
```
|
|
1188
|
+
|
|
1135
1189
|
### Assets
|
|
1136
1190
|
|
|
1137
1191
|
The following `webpack.config.js` can load CSS files, embed small PNG/JPG/GIF/SVG images as well as fonts as [Data URLs](https://tools.ietf.org/html/rfc2397) and copy larger files to the output directory.
|
|
@@ -15,6 +15,25 @@ function visitor(result, parsedResults, node, key) {
|
|
|
15
15
|
// Convert only top-level @import
|
|
16
16
|
if (node.parent.type !== "root") {
|
|
17
17
|
return;
|
|
18
|
+
}
|
|
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);
|
|
23
|
+
|
|
24
|
+
if (matched && matched[2] === "true") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const prevNode = node.prev();
|
|
30
|
+
|
|
31
|
+
if (prevNode && prevNode.type === "comment") {
|
|
32
|
+
const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
|
|
33
|
+
|
|
34
|
+
if (matched && matched[2] === "true") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
18
37
|
} // Nodes do not exists - `@import url('http://') :root {}`
|
|
19
38
|
|
|
20
39
|
|
|
@@ -35,18 +35,82 @@ function shouldHandleRule(rule, node, result) {
|
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
|
|
39
|
+
if (index === 0 && typeof inBetween !== "undefined") {
|
|
40
|
+
return inBetween;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let prevValueNode = nodes[index - 1];
|
|
44
|
+
|
|
45
|
+
if (!prevValueNode) {
|
|
46
|
+
// eslint-disable-next-line consistent-return
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (prevValueNode.type === "space") {
|
|
51
|
+
if (!nodes[index - 2]) {
|
|
52
|
+
// eslint-disable-next-line consistent-return
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
prevValueNode = nodes[index - 2];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (prevValueNode.type !== "comment") {
|
|
60
|
+
// eslint-disable-next-line consistent-return
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const matched = prevValueNode.value.match(_utils.webpackIgnoreCommentRegexp);
|
|
65
|
+
return matched && matched[2] === "true";
|
|
66
|
+
}
|
|
67
|
+
|
|
38
68
|
function visitor(result, parsedResults, node, key) {
|
|
39
69
|
if (!needParseDeclaration.test(node[key])) {
|
|
40
70
|
return;
|
|
41
71
|
}
|
|
42
72
|
|
|
43
|
-
const parsed = (0, _postcssValueParser.default)(node[key]);
|
|
44
|
-
|
|
73
|
+
const parsed = (0, _postcssValueParser.default)(typeof node.raws.value === "undefined" ? node[key] : node.raws.value.raw);
|
|
74
|
+
let inBetween;
|
|
75
|
+
|
|
76
|
+
if (typeof node.raws.between !== "undefined") {
|
|
77
|
+
const lastCommentIndex = node.raws.between.lastIndexOf("/*");
|
|
78
|
+
const matched = node.raws.between.slice(lastCommentIndex).match(_utils.webpackIgnoreCommentRegexp);
|
|
79
|
+
|
|
80
|
+
if (matched) {
|
|
81
|
+
inBetween = matched[2] === "true";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let isIgnoreOnDeclaration = false;
|
|
86
|
+
const prevNode = node.prev();
|
|
87
|
+
|
|
88
|
+
if (prevNode && prevNode.type === "comment") {
|
|
89
|
+
const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
|
|
90
|
+
|
|
91
|
+
if (matched) {
|
|
92
|
+
isIgnoreOnDeclaration = matched[2] === "true";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let needIgnore;
|
|
97
|
+
parsed.walk((valueNode, index, valueNodes) => {
|
|
45
98
|
if (valueNode.type !== "function") {
|
|
46
99
|
return;
|
|
47
100
|
}
|
|
48
101
|
|
|
49
102
|
if (isUrlFunc.test(valueNode.value)) {
|
|
103
|
+
needIgnore = getWebpackIgnoreCommentValue(index, valueNodes, inBetween);
|
|
104
|
+
|
|
105
|
+
if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
|
|
106
|
+
if (needIgnore) {
|
|
107
|
+
// eslint-disable-next-line no-undefined
|
|
108
|
+
needIgnore = undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
50
114
|
const {
|
|
51
115
|
nodes
|
|
52
116
|
} = valueNode;
|
|
@@ -71,13 +135,25 @@ function visitor(result, parsedResults, node, key) {
|
|
|
71
135
|
|
|
72
136
|
return false;
|
|
73
137
|
} else if (isImageSetFunc.test(valueNode.value)) {
|
|
74
|
-
for (const nNode of valueNode.nodes) {
|
|
138
|
+
for (const [innerIndex, nNode] of valueNode.nodes.entries()) {
|
|
75
139
|
const {
|
|
76
140
|
type,
|
|
77
141
|
value
|
|
78
142
|
} = nNode;
|
|
79
143
|
|
|
80
144
|
if (type === "function" && isUrlFunc.test(value)) {
|
|
145
|
+
needIgnore = getWebpackIgnoreCommentValue(innerIndex, valueNode.nodes);
|
|
146
|
+
|
|
147
|
+
if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
|
|
148
|
+
if (needIgnore) {
|
|
149
|
+
// eslint-disable-next-line no-undefined
|
|
150
|
+
needIgnore = undefined;
|
|
151
|
+
} // eslint-disable-next-line no-continue
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
81
157
|
const {
|
|
82
158
|
nodes
|
|
83
159
|
} = nNode;
|
|
@@ -98,6 +174,18 @@ function visitor(result, parsedResults, node, key) {
|
|
|
98
174
|
});
|
|
99
175
|
}
|
|
100
176
|
} else if (type === "string") {
|
|
177
|
+
needIgnore = getWebpackIgnoreCommentValue(innerIndex, valueNode.nodes);
|
|
178
|
+
|
|
179
|
+
if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
|
|
180
|
+
if (needIgnore) {
|
|
181
|
+
// eslint-disable-next-line no-undefined
|
|
182
|
+
needIgnore = undefined;
|
|
183
|
+
} // eslint-disable-next-line no-continue
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
|
|
101
189
|
const rule = {
|
|
102
190
|
node: nNode,
|
|
103
191
|
url: value,
|
package/dist/utils.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.getExportCode = getExportCode;
|
|
|
21
21
|
exports.resolveRequests = resolveRequests;
|
|
22
22
|
exports.isUrlRequestable = isUrlRequestable;
|
|
23
23
|
exports.sort = sort;
|
|
24
|
+
exports.webpackIgnoreCommentRegexp = void 0;
|
|
24
25
|
|
|
25
26
|
var _url = require("url");
|
|
26
27
|
|
|
@@ -49,6 +50,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
49
50
|
const whitespace = "[\\x20\\t\\r\\n\\f]";
|
|
50
51
|
const unescapeRegExp = new RegExp(`\\\\([\\da-f]{1,6}${whitespace}?|(${whitespace})|.)`, "ig");
|
|
51
52
|
const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
|
|
53
|
+
const webpackIgnoreCommentRegexp = /webpackIgnore:(\s+)?(true|false)/;
|
|
54
|
+
exports.webpackIgnoreCommentRegexp = webpackIgnoreCommentRegexp;
|
|
52
55
|
|
|
53
56
|
function unescape(str) {
|
|
54
57
|
return str.replace(unescapeRegExp, (_, escaped, escapedWhitespace) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "css loader module for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/css-loader",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"cssesc": "^3.0.0",
|
|
48
48
|
"icss-utils": "^5.1.0",
|
|
49
49
|
"loader-utils": "^2.0.0",
|
|
50
|
-
"postcss": "^8.2.
|
|
50
|
+
"postcss": "^8.2.6",
|
|
51
51
|
"postcss-modules-extract-imports": "^3.0.0",
|
|
52
52
|
"postcss-modules-local-by-default": "^4.0.0",
|
|
53
53
|
"postcss-modules-scope": "^3.0.0",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"semver": "^7.3.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@babel/cli": "^7.12.
|
|
61
|
-
"@babel/core": "^7.12.
|
|
62
|
-
"@babel/preset-env": "^7.12.
|
|
60
|
+
"@babel/cli": "^7.12.17",
|
|
61
|
+
"@babel/core": "^7.12.17",
|
|
62
|
+
"@babel/preset-env": "^7.12.17",
|
|
63
63
|
"@commitlint/cli": "^11.0.0",
|
|
64
64
|
"@commitlint/config-conventional": "^11.0.0",
|
|
65
65
|
"@webpack-contrib/defaults": "^6.3.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"del": "^6.0.0",
|
|
70
70
|
"del-cli": "^3.0.1",
|
|
71
71
|
"es-check": "^5.2.0",
|
|
72
|
-
"eslint": "^7.
|
|
72
|
+
"eslint": "^7.20.0",
|
|
73
73
|
"eslint-config-prettier": "^7.2.0",
|
|
74
74
|
"eslint-plugin-import": "^2.22.1",
|
|
75
75
|
"file-loader": "^6.2.0",
|
|
@@ -77,22 +77,22 @@
|
|
|
77
77
|
"jest": "^26.6.3",
|
|
78
78
|
"less": "^4.1.1",
|
|
79
79
|
"less-loader": "^7.1.0",
|
|
80
|
-
"lint-staged": "^10.5.
|
|
80
|
+
"lint-staged": "^10.5.4",
|
|
81
81
|
"memfs": "^3.2.0",
|
|
82
|
-
"mini-css-extract-plugin": "^1.3.
|
|
82
|
+
"mini-css-extract-plugin": "^1.3.8",
|
|
83
83
|
"npm-run-all": "^4.1.5",
|
|
84
84
|
"postcss-loader": "^4.0.4",
|
|
85
85
|
"postcss-preset-env": "^6.7.0",
|
|
86
86
|
"prettier": "^2.1.2",
|
|
87
|
-
"sass": "^1.32.
|
|
87
|
+
"sass": "^1.32.8",
|
|
88
88
|
"sass-loader": "^10.1.0",
|
|
89
|
-
"standard-version": "^9.
|
|
89
|
+
"standard-version": "^9.1.1",
|
|
90
90
|
"strip-ansi": "^6.0.0",
|
|
91
91
|
"style-loader": "^2.0.0",
|
|
92
92
|
"stylus": "^0.54.8",
|
|
93
93
|
"stylus-loader": "^4.3.0",
|
|
94
94
|
"url-loader": "^4.1.1",
|
|
95
|
-
"webpack": "^5.
|
|
95
|
+
"webpack": "^5.23.0"
|
|
96
96
|
},
|
|
97
97
|
"keywords": [
|
|
98
98
|
"webpack",
|