css-loader 6.1.0 → 6.5.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 +302 -72
- package/dist/index.js +32 -32
- package/dist/options.json +18 -6
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/postcss-icss-parser.js +14 -7
- package/dist/plugins/postcss-import-parser.js +93 -23
- package/dist/plugins/postcss-url-parser.js +47 -42
- package/dist/runtime/api.js +53 -17
- package/dist/runtime/getUrl.js +1 -5
- package/dist/runtime/noSourceMaps.js +5 -0
- package/dist/runtime/sourceMaps.js +22 -0
- package/dist/utils.js +302 -151
- package/package.json +6 -6
- package/dist/runtime/cssWithMappingToString.js +0 -36
package/README.md
CHANGED
|
@@ -54,69 +54,19 @@ module.exports = {
|
|
|
54
54
|
|
|
55
55
|
And run `webpack` via your preferred method.
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
You can also use the css-loader results directly as a string, such as in Angular's component style.
|
|
60
|
-
|
|
61
|
-
**webpack.config.js**
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
module.exports = {
|
|
65
|
-
module: {
|
|
66
|
-
rules: [
|
|
67
|
-
{
|
|
68
|
-
test: /\.css$/i,
|
|
69
|
-
use: ["to-string-loader", "css-loader"],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
or
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
const css = require("./test.css").toString();
|
|
80
|
-
|
|
81
|
-
console.log(css); // {String}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
If there are SourceMaps, they will also be included in the result string.
|
|
85
|
-
|
|
86
|
-
If, for one reason or another, you need to extract CSS as a
|
|
87
|
-
plain string resource (i.e. not wrapped in a JS module) you
|
|
88
|
-
might want to check out the [extract-loader](https://github.com/peerigon/extract-loader).
|
|
89
|
-
It's useful when you, for instance, need to post process the CSS as a string.
|
|
90
|
-
|
|
91
|
-
**webpack.config.js**
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
module.exports = {
|
|
95
|
-
module: {
|
|
96
|
-
rules: [
|
|
97
|
-
{
|
|
98
|
-
test: /\.css$/i,
|
|
99
|
-
use: [
|
|
100
|
-
"handlebars-loader", // handlebars loader expects raw resource string
|
|
101
|
-
"extract-loader",
|
|
102
|
-
"css-loader",
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
```
|
|
57
|
+
If, for one reason or another, you need to extract CSS as a file (i.e. do not store CSS in a JS module) you might want to check out the [recommend example](https://github.com/webpack-contrib/css-loader#recommend).
|
|
109
58
|
|
|
110
59
|
## Options
|
|
111
60
|
|
|
112
|
-
| Name |
|
|
113
|
-
| :-----------------------------------: |
|
|
114
|
-
| **[`url`](#url)** |
|
|
115
|
-
| **[`import`](#import)** |
|
|
116
|
-
| **[`modules`](#modules)** |
|
|
117
|
-
| **[`sourceMap`](#sourcemap)** |
|
|
118
|
-
| **[`importLoaders`](#importloaders)** |
|
|
119
|
-
| **[`esModule`](#esmodule)** |
|
|
61
|
+
| Name | Type | Default | Description |
|
|
62
|
+
| :-----------------------------------: | :------------------------------------------: | :----------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
63
|
+
| **[`url`](#url)** | `{Boolean\|Object}` | `true` | Allows to enables/disables `url()`/`image-set()` functions handling |
|
|
64
|
+
| **[`import`](#import)** | `{Boolean\|Object}` | `true` | Allows to enables/disables `@import` at-rules handling |
|
|
65
|
+
| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Allows to enables/disables or setup CSS Modules options |
|
|
66
|
+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
|
|
67
|
+
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports |
|
|
68
|
+
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
|
|
69
|
+
| **[`exportType`](#exporttype)** | `{'array' \| 'string' \| 'css-style-sheet'}` | `array` | Allows exporting styles as array with modules, string or [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)) |
|
|
120
70
|
|
|
121
71
|
### `url`
|
|
122
72
|
|
|
@@ -745,13 +695,14 @@ For more information on options see:
|
|
|
745
695
|
|
|
746
696
|
Supported template strings:
|
|
747
697
|
|
|
748
|
-
- [name] the basename of the resource
|
|
749
|
-
- [
|
|
750
|
-
- [
|
|
751
|
-
- [
|
|
752
|
-
- [
|
|
753
|
-
- [
|
|
754
|
-
- [
|
|
698
|
+
- `[name]` the basename of the resource
|
|
699
|
+
- `[folder]` the folder the resource relative to the `compiler.context` option or `modules.localIdentContext` option.
|
|
700
|
+
- `[path]` the path of the resource relative to the `compiler.context` option or `modules.localIdentContext` option.
|
|
701
|
+
- `[file]` - filename and path.
|
|
702
|
+
- `[ext]` - extension with leading `.`.
|
|
703
|
+
- `[hash]` - the hash of the string, generated based on `localIdentHashSalt`, `localIdentHashFunction`, `localIdentHashDigest`, `localIdentHashDigestLength`, `localIdentContext`, `resourcePath` and `exportName`
|
|
704
|
+
- `[<hashFunction>:hash:<hashDigest>:<hashDigestLength>]` - hash with hash settings.
|
|
705
|
+
- `[local]` - original class.
|
|
755
706
|
|
|
756
707
|
Recommendations:
|
|
757
708
|
|
|
@@ -1031,6 +982,9 @@ module.exports = {
|
|
|
1031
982
|
};
|
|
1032
983
|
```
|
|
1033
984
|
|
|
985
|
+
To set a custom name for namedExport, can use [`exportLocalsConvention`](#exportLocalsConvention) option as a function.
|
|
986
|
+
Example below in the [`examples`](#examples) section.
|
|
987
|
+
|
|
1034
988
|
##### `exportGlobals`
|
|
1035
989
|
|
|
1036
990
|
Type: `Boolean`
|
|
@@ -1060,11 +1014,13 @@ module.exports = {
|
|
|
1060
1014
|
|
|
1061
1015
|
##### `exportLocalsConvention`
|
|
1062
1016
|
|
|
1063
|
-
Type: `String`
|
|
1017
|
+
Type: `String|Function`
|
|
1064
1018
|
Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `asIs`
|
|
1065
1019
|
|
|
1066
1020
|
Style of exported class names.
|
|
1067
1021
|
|
|
1022
|
+
###### `String`
|
|
1023
|
+
|
|
1068
1024
|
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
1069
1025
|
|
|
1070
1026
|
> ⚠ Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
|
|
@@ -1110,6 +1066,58 @@ module.exports = {
|
|
|
1110
1066
|
};
|
|
1111
1067
|
```
|
|
1112
1068
|
|
|
1069
|
+
###### `Function`
|
|
1070
|
+
|
|
1071
|
+
**webpack.config.js**
|
|
1072
|
+
|
|
1073
|
+
```js
|
|
1074
|
+
module.exports = {
|
|
1075
|
+
module: {
|
|
1076
|
+
rules: [
|
|
1077
|
+
{
|
|
1078
|
+
test: /\.css$/i,
|
|
1079
|
+
loader: "css-loader",
|
|
1080
|
+
options: {
|
|
1081
|
+
modules: {
|
|
1082
|
+
exportLocalsConvention: function (name) {
|
|
1083
|
+
return name.replace(/-/g, "_");
|
|
1084
|
+
},
|
|
1085
|
+
},
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
],
|
|
1089
|
+
},
|
|
1090
|
+
};
|
|
1091
|
+
```
|
|
1092
|
+
|
|
1093
|
+
**webpack.config.js**
|
|
1094
|
+
|
|
1095
|
+
```js
|
|
1096
|
+
module.exports = {
|
|
1097
|
+
module: {
|
|
1098
|
+
rules: [
|
|
1099
|
+
{
|
|
1100
|
+
test: /\.css$/i,
|
|
1101
|
+
loader: "css-loader",
|
|
1102
|
+
options: {
|
|
1103
|
+
modules: {
|
|
1104
|
+
exportLocalsConvention: function (name) {
|
|
1105
|
+
return [
|
|
1106
|
+
name.replace(/-/g, "_"),
|
|
1107
|
+
// dashesCamelCase
|
|
1108
|
+
name.replace(/-+(\w)/g, (match, firstLetter) =>
|
|
1109
|
+
firstLetter.toUpperCase()
|
|
1110
|
+
),
|
|
1111
|
+
];
|
|
1112
|
+
},
|
|
1113
|
+
},
|
|
1114
|
+
},
|
|
1115
|
+
},
|
|
1116
|
+
],
|
|
1117
|
+
},
|
|
1118
|
+
};
|
|
1119
|
+
```
|
|
1120
|
+
|
|
1113
1121
|
##### `exportOnlyLocals`
|
|
1114
1122
|
|
|
1115
1123
|
Type: `Boolean`
|
|
@@ -1233,6 +1241,203 @@ module.exports = {
|
|
|
1233
1241
|
};
|
|
1234
1242
|
```
|
|
1235
1243
|
|
|
1244
|
+
### `exportType`
|
|
1245
|
+
|
|
1246
|
+
Type: `'array' | 'string' | 'css-style-sheet'`
|
|
1247
|
+
Default: `'array'`
|
|
1248
|
+
|
|
1249
|
+
Allows exporting styles as array with modules, string or [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).
|
|
1250
|
+
Default value is `'array'`, i.e. loader exports array of modules with specific API which is used in `style-loader` or other.
|
|
1251
|
+
|
|
1252
|
+
**webpack.config.js**
|
|
1253
|
+
|
|
1254
|
+
```js
|
|
1255
|
+
module.exports = {
|
|
1256
|
+
module: {
|
|
1257
|
+
rules: [
|
|
1258
|
+
{
|
|
1259
|
+
assert: { type: "css" },
|
|
1260
|
+
loader: "css-loader",
|
|
1261
|
+
options: {
|
|
1262
|
+
exportType: "css-style-sheet",
|
|
1263
|
+
},
|
|
1264
|
+
},
|
|
1265
|
+
],
|
|
1266
|
+
},
|
|
1267
|
+
};
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
**src/index.js**
|
|
1271
|
+
|
|
1272
|
+
```js
|
|
1273
|
+
import sheet from "./styles.css" assert { type: "css" };
|
|
1274
|
+
|
|
1275
|
+
document.adoptedStyleSheets = [sheet];
|
|
1276
|
+
shadowRoot.adoptedStyleSheets = [sheet];
|
|
1277
|
+
```
|
|
1278
|
+
|
|
1279
|
+
#### `'array'`
|
|
1280
|
+
|
|
1281
|
+
The default export is array of modules with specific API which is used in `style-loader` or other.
|
|
1282
|
+
|
|
1283
|
+
**webpack.config.js**
|
|
1284
|
+
|
|
1285
|
+
```js
|
|
1286
|
+
module.exports = {
|
|
1287
|
+
module: {
|
|
1288
|
+
rules: [
|
|
1289
|
+
{
|
|
1290
|
+
test: /\.(sa|sc|c)ss$/i,
|
|
1291
|
+
use: ["style-loader", "css-loader", "postcss-loader", "sass-loader"],
|
|
1292
|
+
},
|
|
1293
|
+
],
|
|
1294
|
+
},
|
|
1295
|
+
};
|
|
1296
|
+
```
|
|
1297
|
+
|
|
1298
|
+
**src/index.js**
|
|
1299
|
+
|
|
1300
|
+
```js
|
|
1301
|
+
// `style-loader` applies styles to DOM
|
|
1302
|
+
import "./styles.css";
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
#### `'string'`
|
|
1306
|
+
|
|
1307
|
+
> ⚠ You don't need [`style-loader`](https://github.com/webpack-contrib/style-loader) anymore, please remove it.
|
|
1308
|
+
> ⚠ The `esModules` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack-contrib/css-loader#modules), by default for locals will be used [named export](https://github.com/webpack-contrib/css-loader#namedexport).
|
|
1309
|
+
|
|
1310
|
+
The default export is `string`.
|
|
1311
|
+
|
|
1312
|
+
**webpack.config.js**
|
|
1313
|
+
|
|
1314
|
+
```js
|
|
1315
|
+
module.exports = {
|
|
1316
|
+
module: {
|
|
1317
|
+
rules: [
|
|
1318
|
+
{
|
|
1319
|
+
test: /\.(sa|sc|c)ss$/i,
|
|
1320
|
+
use: ["css-loader", "postcss-loader", "sass-loader"],
|
|
1321
|
+
},
|
|
1322
|
+
],
|
|
1323
|
+
},
|
|
1324
|
+
};
|
|
1325
|
+
```
|
|
1326
|
+
|
|
1327
|
+
**src/index.js**
|
|
1328
|
+
|
|
1329
|
+
```js
|
|
1330
|
+
import sheet from "./styles.css";
|
|
1331
|
+
|
|
1332
|
+
console.log(sheet);
|
|
1333
|
+
```
|
|
1334
|
+
|
|
1335
|
+
#### `'css-style-sheet'`
|
|
1336
|
+
|
|
1337
|
+
> ⚠ `@import` rules not yet allowed, more [information](https://web.dev/css-module-scripts/#@import-rules-not-yet-allowed)
|
|
1338
|
+
> ⚠ You don't need [`style-loader`](https://github.com/webpack-contrib/style-loader) anymore, please remove it.
|
|
1339
|
+
> ⚠ The `esModules` option should be enabled if you want to use it with [`CSS modules`](https://github.com/webpack-contrib/css-loader#modules), by default for locals will be used [named export](https://github.com/webpack-contrib/css-loader#namedexport).
|
|
1340
|
+
> ⚠ Source maps are not currently supported in `Chrome` due [bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1174094&q=CSSStyleSheet%20source%20maps&can=2)
|
|
1341
|
+
|
|
1342
|
+
The default export is a [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).
|
|
1343
|
+
|
|
1344
|
+
Useful for [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) and shadow DOM.
|
|
1345
|
+
|
|
1346
|
+
More information:
|
|
1347
|
+
|
|
1348
|
+
- [Using CSS Module Scripts to import stylesheets](https://web.dev/css-module-scripts/)
|
|
1349
|
+
- [Constructable Stylesheets: seamless reusable styles](https://developers.google.com/web/updates/2019/02/constructable-stylesheets)
|
|
1350
|
+
|
|
1351
|
+
**webpack.config.js**
|
|
1352
|
+
|
|
1353
|
+
```js
|
|
1354
|
+
module.exports = {
|
|
1355
|
+
module: {
|
|
1356
|
+
rules: [
|
|
1357
|
+
{
|
|
1358
|
+
assert: { type: "css" },
|
|
1359
|
+
loader: "css-loader",
|
|
1360
|
+
options: {
|
|
1361
|
+
exportType: "css-style-sheet",
|
|
1362
|
+
},
|
|
1363
|
+
},
|
|
1364
|
+
|
|
1365
|
+
// For Sass/SCSS:
|
|
1366
|
+
//
|
|
1367
|
+
// {
|
|
1368
|
+
// assert: { type: "css" },
|
|
1369
|
+
// rules: [
|
|
1370
|
+
// {
|
|
1371
|
+
// loader: "css-loader",
|
|
1372
|
+
// options: {
|
|
1373
|
+
// exportType: "css-style-sheet",
|
|
1374
|
+
// // Other options
|
|
1375
|
+
// },
|
|
1376
|
+
// },
|
|
1377
|
+
// {
|
|
1378
|
+
// loader: "sass-loader",
|
|
1379
|
+
// options: {
|
|
1380
|
+
// // Other options
|
|
1381
|
+
// },
|
|
1382
|
+
// },
|
|
1383
|
+
// ],
|
|
1384
|
+
// },
|
|
1385
|
+
],
|
|
1386
|
+
},
|
|
1387
|
+
};
|
|
1388
|
+
```
|
|
1389
|
+
|
|
1390
|
+
**src/index.js**
|
|
1391
|
+
|
|
1392
|
+
```js
|
|
1393
|
+
// Example for Sass/SCSS:
|
|
1394
|
+
// import sheet from "./styles.scss" assert { type: "css" };
|
|
1395
|
+
|
|
1396
|
+
// Example for CSS modules:
|
|
1397
|
+
// import sheet, { myClass } from "./styles.scss" assert { type: "css" };
|
|
1398
|
+
|
|
1399
|
+
// Example for CSS:
|
|
1400
|
+
import sheet from "./styles.css" assert { type: "css" };
|
|
1401
|
+
|
|
1402
|
+
document.adoptedStyleSheets = [sheet];
|
|
1403
|
+
shadowRoot.adoptedStyleSheets = [sheet];
|
|
1404
|
+
```
|
|
1405
|
+
|
|
1406
|
+
For migration purposes, you can use the following configuration:
|
|
1407
|
+
|
|
1408
|
+
```js
|
|
1409
|
+
module.exports = {
|
|
1410
|
+
module: {
|
|
1411
|
+
rules: [
|
|
1412
|
+
{
|
|
1413
|
+
test: /\.css$/i,
|
|
1414
|
+
oneOf: [
|
|
1415
|
+
{
|
|
1416
|
+
assert: { type: "css" },
|
|
1417
|
+
loader: "css-loader",
|
|
1418
|
+
options: {
|
|
1419
|
+
exportType: "css-style-sheet",
|
|
1420
|
+
// Other options
|
|
1421
|
+
},
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
use: [
|
|
1425
|
+
"style-loader",
|
|
1426
|
+
{
|
|
1427
|
+
loader: "css-loader",
|
|
1428
|
+
options: {
|
|
1429
|
+
// Other options
|
|
1430
|
+
},
|
|
1431
|
+
},
|
|
1432
|
+
],
|
|
1433
|
+
},
|
|
1434
|
+
],
|
|
1435
|
+
},
|
|
1436
|
+
],
|
|
1437
|
+
},
|
|
1438
|
+
};
|
|
1439
|
+
```
|
|
1440
|
+
|
|
1236
1441
|
## Examples
|
|
1237
1442
|
|
|
1238
1443
|
### Recommend
|
|
@@ -1253,7 +1458,7 @@ module.exports = {
|
|
|
1253
1458
|
module: {
|
|
1254
1459
|
rules: [
|
|
1255
1460
|
{
|
|
1256
|
-
test: /\.(sa|sc|c)ss
|
|
1461
|
+
test: /\.(sa|sc|c)ss$/i,
|
|
1257
1462
|
use: [
|
|
1258
1463
|
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
|
|
1259
1464
|
"css-loader",
|
|
@@ -1434,6 +1639,31 @@ module.exports = {
|
|
|
1434
1639
|
};
|
|
1435
1640
|
```
|
|
1436
1641
|
|
|
1642
|
+
### Named export with custom export names
|
|
1643
|
+
|
|
1644
|
+
**webpack.config.js**
|
|
1645
|
+
|
|
1646
|
+
```js
|
|
1647
|
+
module.exports = {
|
|
1648
|
+
module: {
|
|
1649
|
+
rules: [
|
|
1650
|
+
{
|
|
1651
|
+
test: /\.css$/i,
|
|
1652
|
+
loader: "css-loader",
|
|
1653
|
+
options: {
|
|
1654
|
+
modules: {
|
|
1655
|
+
namedExport: true,
|
|
1656
|
+
exportLocalsConvention: function (name) {
|
|
1657
|
+
return name.replace(/-/g, "_");
|
|
1658
|
+
},
|
|
1659
|
+
},
|
|
1660
|
+
},
|
|
1661
|
+
},
|
|
1662
|
+
],
|
|
1663
|
+
},
|
|
1664
|
+
};
|
|
1665
|
+
```
|
|
1666
|
+
|
|
1437
1667
|
### Separating `Interoperable CSS`-only and `CSS Module` features
|
|
1438
1668
|
|
|
1439
1669
|
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 `mode` 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.
|
|
@@ -1451,8 +1681,8 @@ module.exports = {
|
|
|
1451
1681
|
// --------
|
|
1452
1682
|
// SCSS ALL EXCEPT MODULES
|
|
1453
1683
|
{
|
|
1454
|
-
test: /\.scss
|
|
1455
|
-
exclude: /\.module\.scss
|
|
1684
|
+
test: /\.scss$/i,
|
|
1685
|
+
exclude: /\.module\.scss$/i,
|
|
1456
1686
|
use: [
|
|
1457
1687
|
{
|
|
1458
1688
|
loader: "style-loader",
|
|
@@ -1474,7 +1704,7 @@ module.exports = {
|
|
|
1474
1704
|
// --------
|
|
1475
1705
|
// SCSS MODULES
|
|
1476
1706
|
{
|
|
1477
|
-
test: /\.module\.scss
|
|
1707
|
+
test: /\.module\.scss$/i,
|
|
1478
1708
|
use: [
|
|
1479
1709
|
{
|
|
1480
1710
|
loader: "style-loader",
|
package/dist/index.js
CHANGED
|
@@ -49,24 +49,23 @@ async function loader(content, map, meta) {
|
|
|
49
49
|
|
|
50
50
|
const importPluginImports = [];
|
|
51
51
|
const importPluginApi = [];
|
|
52
|
+
let isSupportAbsoluteURL = false; // TODO enable by default in the next major release
|
|
53
|
+
|
|
54
|
+
if (this._compilation && this._compilation.options && this._compilation.options.experiments && this._compilation.options.experiments.buildHttp) {
|
|
55
|
+
isSupportAbsoluteURL = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const isSupportDataURL = options.esModule && Boolean("fsStartTime" in this._compiler);
|
|
52
59
|
|
|
53
60
|
if ((0, _utils.shouldUseImportPlugin)(options)) {
|
|
54
|
-
const resolver = this.getResolve({
|
|
55
|
-
dependencyType: "css",
|
|
56
|
-
conditionNames: ["style"],
|
|
57
|
-
mainFields: ["css", "style", "main", "..."],
|
|
58
|
-
mainFiles: ["index", "..."],
|
|
59
|
-
extensions: [".css", "..."],
|
|
60
|
-
preferRelative: true
|
|
61
|
-
});
|
|
62
61
|
plugins.push((0, _plugins.importParser)({
|
|
62
|
+
isSupportAbsoluteURL: false,
|
|
63
|
+
isSupportDataURL: false,
|
|
64
|
+
isCSSStyleSheet: options.exportType === "css-style-sheet",
|
|
65
|
+
loaderContext: this,
|
|
63
66
|
imports: importPluginImports,
|
|
64
67
|
api: importPluginApi,
|
|
65
|
-
|
|
66
|
-
rootContext: this.rootContext,
|
|
67
|
-
resourcePath: this.resourcePath,
|
|
68
|
-
filter: (0, _utils.getFilter)(options.import.filter, this.resourcePath),
|
|
69
|
-
resolver,
|
|
68
|
+
filter: options.import.filter,
|
|
70
69
|
urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
|
|
71
70
|
}));
|
|
72
71
|
}
|
|
@@ -75,22 +74,21 @@ async function loader(content, map, meta) {
|
|
|
75
74
|
|
|
76
75
|
if ((0, _utils.shouldUseURLPlugin)(options)) {
|
|
77
76
|
const needToResolveURL = !options.esModule;
|
|
78
|
-
const isSupportDataURLInNewURL = options.esModule && Boolean("fsStartTime" in this._compiler);
|
|
79
77
|
plugins.push((0, _plugins.urlParser)({
|
|
78
|
+
isSupportAbsoluteURL,
|
|
79
|
+
isSupportDataURL,
|
|
80
80
|
imports: urlPluginImports,
|
|
81
81
|
replacements,
|
|
82
82
|
context: this.context,
|
|
83
83
|
rootContext: this.rootContext,
|
|
84
84
|
filter: (0, _utils.getFilter)(options.url.filter, this.resourcePath),
|
|
85
|
-
needToResolveURL,
|
|
86
85
|
resolver: needToResolveURL ? this.getResolve({
|
|
87
86
|
mainFiles: [],
|
|
88
87
|
extensions: []
|
|
89
88
|
}) : // eslint-disable-next-line no-undefined
|
|
90
89
|
undefined,
|
|
91
|
-
urlHandler: url => (0, _utils.stringifyRequest)(this, url)
|
|
92
|
-
|
|
93
|
-
isSupportDataURLInNewURL
|
|
90
|
+
urlHandler: url => (0, _utils.stringifyRequest)(this, url) // Support data urls as input in new URL added in webpack@5.38.0
|
|
91
|
+
|
|
94
92
|
}));
|
|
95
93
|
}
|
|
96
94
|
|
|
@@ -99,22 +97,12 @@ async function loader(content, map, meta) {
|
|
|
99
97
|
const needToUseIcssPlugin = (0, _utils.shouldUseIcssPlugin)(options);
|
|
100
98
|
|
|
101
99
|
if (needToUseIcssPlugin) {
|
|
102
|
-
const icssResolver = this.getResolve({
|
|
103
|
-
dependencyType: "icss",
|
|
104
|
-
conditionNames: ["style"],
|
|
105
|
-
extensions: ["..."],
|
|
106
|
-
mainFields: ["css", "style", "main", "..."],
|
|
107
|
-
mainFiles: ["index", "..."],
|
|
108
|
-
preferRelative: true
|
|
109
|
-
});
|
|
110
100
|
plugins.push((0, _plugins.icssParser)({
|
|
101
|
+
loaderContext: this,
|
|
111
102
|
imports: icssPluginImports,
|
|
112
103
|
api: icssPluginApi,
|
|
113
104
|
replacements,
|
|
114
105
|
exports,
|
|
115
|
-
context: this.context,
|
|
116
|
-
rootContext: this.rootContext,
|
|
117
|
-
resolver: icssResolver,
|
|
118
106
|
urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
|
|
119
107
|
}));
|
|
120
108
|
} // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
|
|
@@ -172,15 +160,27 @@ async function loader(content, map, meta) {
|
|
|
172
160
|
|
|
173
161
|
if (options.sourceMap) {
|
|
174
162
|
imports.unshift({
|
|
175
|
-
type: "api_sourcemap_import",
|
|
176
163
|
importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
|
|
177
|
-
url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/
|
|
164
|
+
url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/sourceMaps"))
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
imports.unshift({
|
|
168
|
+
importName: "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___",
|
|
169
|
+
url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/noSourceMaps"))
|
|
178
170
|
});
|
|
179
171
|
}
|
|
180
172
|
}
|
|
181
173
|
|
|
182
174
|
const importCode = (0, _utils.getImportCode)(imports, options);
|
|
183
|
-
|
|
175
|
+
let moduleCode;
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
callback(error);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
184
|
const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options);
|
|
185
185
|
callback(null, `${importCode}${moduleCode}${exportCode}`);
|
|
186
186
|
}
|
package/dist/options.json
CHANGED
|
@@ -145,12 +145,19 @@
|
|
|
145
145
|
"exportLocalsConvention": {
|
|
146
146
|
"description": "Style of exported classnames.",
|
|
147
147
|
"link": "https://github.com/webpack-contrib/css-loader#localsconvention",
|
|
148
|
-
"
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
"anyOf": [
|
|
149
|
+
{
|
|
150
|
+
"enum": [
|
|
151
|
+
"asIs",
|
|
152
|
+
"camelCase",
|
|
153
|
+
"camelCaseOnly",
|
|
154
|
+
"dashes",
|
|
155
|
+
"dashesOnly"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"instanceof": "Function"
|
|
160
|
+
}
|
|
154
161
|
]
|
|
155
162
|
},
|
|
156
163
|
"exportOnlyLocals": {
|
|
@@ -186,6 +193,11 @@
|
|
|
186
193
|
"description": "Use the ES modules syntax.",
|
|
187
194
|
"link": "https://github.com/webpack-contrib/css-loader#esmodule",
|
|
188
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"]
|
|
189
201
|
}
|
|
190
202
|
},
|
|
191
203
|
"type": "object"
|
package/dist/plugins/index.js
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "icssParser", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _postcssIcssParser.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "importParser", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _postcssImportParser.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "urlParser", {
|
|
@@ -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;
|