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
Loader to process CSS with[`PostCSS`](https://github.com/postcss/postcss).
39
+
A loader to process CSS using[`PostCSS`](https://github.com/postcss/postcss).
40
40
41
41
## Getting Started
42
42
@@ -60,7 +60,7 @@ or
60
60
pnpm add -D postcss-loader postcss
61
61
```
62
62
63
-
Then add the plugin to your `webpack`config. For example:
63
+
Then add the loader to your `webpack`configuration. For example:
64
64
65
65
> In the following configuration the plugin [`postcss-preset-env`](https://github.com/csstools/postcss-preset-env) is used, which is not installed by default.
66
66
@@ -137,7 +137,7 @@ module.exports = {
137
137
};
138
138
```
139
139
140
-
And run `webpack` via your preferred method.
140
+
Finally, run `webpack`using the method you normally use (e.g., via CLI or an npm script).
141
141
142
142
## Options
143
143
@@ -156,7 +156,7 @@ type execute = boolean;
156
156
157
157
Default: `undefined`
158
158
159
-
Enable PostCSS Parser support in`CSS-in-JS`.
159
+
Enable PostCSS parser support for`CSS-in-JS`.
160
160
If you use JS styles the [`postcss-js`](https://github.com/postcss/postcss-js) parser, add the `execute` option.
161
161
162
162
**webpack.config.js**
@@ -215,17 +215,16 @@ export type PostCSSLoaderOptions =
215
215
216
216
Default: `undefined`
217
217
218
-
Allows to set [`PostCSS options`](https://postcss.org/api/#processoptions) and plugins.
218
+
Allows you to set [`PostCSS options`](https://postcss.org/api/#processoptions) and plugins.
219
219
220
220
All `PostCSS` options are supported.
221
221
There is the special `config` option for config files. How it works and how it can be configured is described below.
222
222
223
223
We recommend do not specify `from`, `to` and `map` options, because this can lead to wrong path in source maps.
224
-
If you need source maps please use the [`sourcemap`](#sourcemap) option.
224
+
If you need source maps please use the [`sourcemap`](#sourcemap) option instead.
225
225
226
-
For large projects, to optimize performance of the loader, it is better to provide `postcssOptions` in loader
227
-
config and specify `config: false`. This approach removes the need to lookup and load external config files multiple
228
-
times during compilation.
226
+
For large projects, to optimize performance of the loader, it is better to provide `postcssOptions` in loader config and specify `config: false`.
227
+
This approach removes the need to lookup and load external config files multiple times during compilation.
229
228
230
229
#### `object`
231
230
@@ -412,17 +411,17 @@ type config = boolean | string;
412
411
413
412
Default: `true`
414
413
415
-
Allows to set options using config files.
414
+
Allows you to set options using config files.
416
415
Options specified in the config file are combined with options passed to the loader, the loader options overwrite options from config.
417
416
418
417
##### Config Files
419
418
420
419
The loader will search up the directory tree for configuration in the following places:
421
420
422
-
-a`postcss` property in `package.json`
423
-
-a`.postcssrc` file in JSON or YAML format
424
-
-a`.postcssrc.json`, `.postcssrc.yaml`, `.postcssrc.yml`, `.postcssrc.js`, or `.postcssrc.cjs` file
425
-
-a`postcss.config.js` or `postcss.config.cjs` CommonJS module exporting an object (**recommended**)
421
+
-A`postcss` property in `package.json`
422
+
-A`.postcssrc` file in JSON or YAML format
423
+
-A`.postcssrc.json`, `.postcssrc.yaml`, `.postcssrc.yml`, `.postcssrc.js`, or `.postcssrc.cjs` file
424
+
-A`postcss.config.js` or `postcss.config.cjs` CommonJS module exporting an object (**recommended**)
426
425
427
426
##### Examples of Config Files
428
427
@@ -517,7 +516,7 @@ Config lookup starts from `path.dirname(file)` and walks the file tree upwards u
517
516
After setting up your `postcss.config.js`, add `postcss-loader` to your `webpack.config.js`.
518
517
You can use it standalone or in conjunction with `css-loader` (recommended).
519
518
520
-
Use it**before**`css-loader` and `style-loader`, but **after** other preprocessor loaders like e.g `sass|less|stylus-loader`, if you use any (since [webpack loaders evaluate right to left/bottom to top](https://webpack.js.org/concepts/loaders/#configuration)).
519
+
Use `postcss-loader`**before**`css-loader` and `style-loader`, but **after** other preprocessor loaders like e.g `sass|less|stylus-loader`, if you use any (since [webpack loaders evaluate right to left/bottom to top](https://webpack.js.org/concepts/loaders/#configuration)).
521
520
522
521
**webpack.config.js** (**recommended**)
523
522
@@ -719,6 +718,8 @@ module.exports = {
719
718
720
719
### SugarSS
721
720
721
+
`SugarSS` is a whitespace-based syntax for PostCSS.
722
+
722
723
You'll need to install `sugarss`:
723
724
724
725
```console
@@ -764,7 +765,7 @@ You'll need to install `autoprefixer`:
764
765
npm install --save-dev autoprefixer
765
766
```
766
767
767
-
Add vendor prefixes to CSS rules using [`autoprefixer`](https://github.com/postcss/autoprefixer).
768
+
Automatically add vendor prefixes to CSS rules using [`autoprefixer`](https://github.com/postcss/autoprefixer).
768
769
769
770
**webpack.config.js**
770
771
@@ -788,7 +789,7 @@ module.exports = {
788
789
[
789
790
"autoprefixer",
790
791
{
791
-
//Options
792
+
//Autoprefixer options (optional)
792
793
},
793
794
],
794
795
],
@@ -852,9 +853,9 @@ module.exports = {
852
853
853
854
### CSS Modules
854
855
855
-
What is`CSS Modules`? Please [read](https://github.com/webpack-contrib/css-loader#modules).
856
+
> What are`CSS Modules`? Please [read here](https://github.com/webpack-contrib/css-loader#modules).
856
857
857
-
No additional options required on the `postcss-loader` side.
858
+
No additional options required on the `postcss-loader` side to support CSS Modules.
858
859
To make them work properly, either add the `css-loader`’s `importLoaders` option.
859
860
860
861
**webpack.config.js**
@@ -884,6 +885,8 @@ module.exports = {
884
885
885
886
### CSS-in-JS and [`postcss-js`](https://github.com/postcss/postcss-js)
886
887
888
+
To process styles written in JavaScript, you can use `postcss-js` as the parser.
889
+
887
890
You'll need to install `postcss-js`:
888
891
889
892
```console
@@ -925,7 +928,7 @@ module.exports = {
925
928
};
926
929
```
927
930
928
-
As result you will be able to write styles in the following way
931
+
As result you will be able to write styles in the following way:
929
932
930
933
```js
931
934
importcolorsfrom"./styles/colors";
@@ -944,13 +947,13 @@ export default {
944
947
> [!WARNING]
945
948
>
946
949
> If you are using Babel you need to do the following in order for the setup to work
947
-
950
+
>
948
951
> 1. Add [`babel-plugin-add-module-exports`](https://github.com/59naga/babel-plugin-add-module-exports) to your configuration.
949
952
> 2. You need to have only one **default** export per style module.
> ✅ This method is ideal when you want to dynamically declare dependencies without relying on result.messages, especially in more complex setups or shared plugin configurations.
1166
+
1152
1167
## Contributing
1153
1168
1154
-
Please take a moment to read our contributing guidelines if you haven't yet done so.
1169
+
We welcome all contributions!
1170
+
If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
0 commit comments