You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also use the css-loader results directly as a string, such as in Angular's component style.
66
-
67
-
**webpack.config.js**
68
-
69
-
```js
70
-
module.exports= {
71
-
module: {
72
-
rules: [
73
-
{
74
-
test:/\.css$/i,
75
-
use: ["to-string-loader", "css-loader"],
76
-
},
77
-
],
78
-
},
79
-
};
80
-
```
81
-
82
-
or
83
-
84
-
```js
85
-
constcss=require("./test.css").toString();
86
-
87
-
console.log(css); // {String}
88
-
```
89
-
90
-
If there are SourceMaps, they will also be included in the result string.
91
-
92
63
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).
|**[`url`](#url)**|`{Boolean\|Object}`|`true`| Allows to enables/disables `url()`/`image-set()` functions handling |
99
-
|**[`import`](#import)**|`{Boolean\|Object}`|`true`| Allows to enables/disables `@import` at-rules handling |
100
-
|**[`modules`](#modules)**|`{Boolean\|String\|Object}`|`{auto: true}`| Allows to enables/disables or setup CSS Modules options |
101
-
|**[`sourceMap`](#sourcemap)**|`{Boolean}`|`compiler.devtool`| Enables/Disables generation of source maps |
102
-
|**[`importLoaders`](#importloaders)**|`{Number}`|`0`| Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports |
103
-
|**[`esModule`](#esmodule)**|`{Boolean}`|`true`| Use ES modules syntax |
|**[`url`](#url)**|`{Boolean\|Object}`|`true`| Allows to enables/disables `url()`/`image-set()` functions handling |
70
+
|**[`import`](#import)**|`{Boolean\|Object}`|`true`| Allows to enables/disables `@import` at-rules handling |
71
+
|**[`modules`](#modules)**|`{Boolean\|String\|Object}`|`{auto: true}`| Allows to enables/disables or setup CSS Modules options |
72
+
|**[`sourceMap`](#sourcemap)**|`{Boolean}`|`compiler.devtool`| Enables/Disables generation of source maps |
73
+
|**[`importLoaders`](#importloaders)**|`{Number}`|`0`| Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports |
74
+
|**[`esModule`](#esmodule)**|`{Boolean}`|`true`| Use ES modules syntax |
75
+
|**[`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)) |
104
76
105
77
### `url`
106
78
@@ -1275,6 +1247,203 @@ module.exports = {
1275
1247
};
1276
1248
```
1277
1249
1250
+
### `exportType`
1251
+
1252
+
Type: `'array' | 'string' | 'css-style-sheet'`
1253
+
Default: `'array'`
1254
+
1255
+
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)).
1256
+
Default value is `'array'`, i.e. loader exports array of modules with specific API which is used in `style-loader` or other.
> ⚠ You don't need [`style-loader`](/loaders/style-loader/) anymore, please remove it.
1314
+
> ⚠ 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).
> ⚠ `@import` rules not yet allowed, more [information](https://web.dev/css-module-scripts/#@import-rules-not-yet-allowed)
1344
+
> ⚠ You don't need [`style-loader`](/loaders/style-loader/) anymore, please remove it.
1345
+
> ⚠ 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).
1346
+
> ⚠ 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)
1347
+
1348
+
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)).
1349
+
1350
+
Useful for [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) and shadow DOM.
1351
+
1352
+
More information:
1353
+
1354
+
-[Using CSS Module Scripts to import stylesheets](https://web.dev/css-module-scripts/)
0 commit comments