Skip to content

Commit 36749e8

Browse files
authored
docs: fix typos and improve clarity in README.md (webpack-contrib#703)
1 parent 26de829 commit 36749e8

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

README.md

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PostCSS chat: [![chat-postcss][chat-postcss]][chat-postcss-url]
3636

3737
# postcss-loader
3838

39-
Loader to process CSS with [`PostCSS`](https://github.com/postcss/postcss).
39+
A loader to process CSS using [`PostCSS`](https://github.com/postcss/postcss).
4040

4141
## Getting Started
4242

@@ -60,7 +60,7 @@ or
6060
pnpm add -D postcss-loader postcss
6161
```
6262

63-
Then add the plugin to your `webpack` config. For example:
63+
Then add the loader to your `webpack` configuration. For example:
6464

6565
> In the following configuration the plugin [`postcss-preset-env`](https://github.com/csstools/postcss-preset-env) is used, which is not installed by default.
6666
@@ -137,7 +137,7 @@ module.exports = {
137137
};
138138
```
139139

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).
141141

142142
## Options
143143

@@ -156,7 +156,7 @@ type execute = boolean;
156156

157157
Default: `undefined`
158158

159-
Enable PostCSS Parser support in `CSS-in-JS`.
159+
Enable PostCSS parser support for `CSS-in-JS`.
160160
If you use JS styles the [`postcss-js`](https://github.com/postcss/postcss-js) parser, add the `execute` option.
161161

162162
**webpack.config.js**
@@ -215,17 +215,16 @@ export type PostCSSLoaderOptions =
215215

216216
Default: `undefined`
217217

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.
219219

220220
All `PostCSS` options are supported.
221221
There is the special `config` option for config files. How it works and how it can be configured is described below.
222222

223223
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.
225225

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.
229228

230229
#### `object`
231230

@@ -412,17 +411,17 @@ type config = boolean | string;
412411

413412
Default: `true`
414413

415-
Allows to set options using config files.
414+
Allows you to set options using config files.
416415
Options specified in the config file are combined with options passed to the loader, the loader options overwrite options from config.
417416

418417
##### Config Files
419418

420419
The loader will search up the directory tree for configuration in the following places:
421420

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**)
426425

427426
##### Examples of Config Files
428427

@@ -517,7 +516,7 @@ Config lookup starts from `path.dirname(file)` and walks the file tree upwards u
517516
After setting up your `postcss.config.js`, add `postcss-loader` to your `webpack.config.js`.
518517
You can use it standalone or in conjunction with `css-loader` (recommended).
519518

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)).
521520

522521
**webpack.config.js** (**recommended**)
523522

@@ -719,6 +718,8 @@ module.exports = {
719718

720719
### SugarSS
721720

721+
`SugarSS` is a whitespace-based syntax for PostCSS.
722+
722723
You'll need to install `sugarss`:
723724

724725
```console
@@ -764,7 +765,7 @@ You'll need to install `autoprefixer`:
764765
npm install --save-dev autoprefixer
765766
```
766767

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).
768769

769770
**webpack.config.js**
770771

@@ -788,7 +789,7 @@ module.exports = {
788789
[
789790
"autoprefixer",
790791
{
791-
// Options
792+
// Autoprefixer options (optional)
792793
},
793794
],
794795
],
@@ -852,9 +853,9 @@ module.exports = {
852853

853854
### CSS Modules
854855

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).
856857
857-
No additional options required on the `postcss-loader` side.
858+
No additional options required on the `postcss-loader` side to support CSS Modules.
858859
To make them work properly, either add the `css-loader`’s `importLoaders` option.
859860

860861
**webpack.config.js**
@@ -884,6 +885,8 @@ module.exports = {
884885

885886
### CSS-in-JS and [`postcss-js`](https://github.com/postcss/postcss-js)
886887

888+
To process styles written in JavaScript, you can use `postcss-js` as the parser.
889+
887890
You'll need to install `postcss-js`:
888891

889892
```console
@@ -925,7 +928,7 @@ module.exports = {
925928
};
926929
```
927930

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:
929932

930933
```js
931934
import colors from "./styles/colors";
@@ -944,13 +947,13 @@ export default {
944947
> [!WARNING]
945948
>
946949
> If you are using Babel you need to do the following in order for the setup to work
947-
950+
>
948951
> 1. Add [`babel-plugin-add-module-exports`](https://github.com/59naga/babel-plugin-add-module-exports) to your configuration.
949952
> 2. You need to have only one **default** export per style module.
950953
951954
### Extract CSS
952955

953-
Using [`mini-css-extract-plugin`](https://github.com/webpack-contrib/mini-css-extract-plugin).
956+
To extract CSS into separate files, use [`mini-css-extract-plugin`](https://github.com/webpack-contrib/mini-css-extract-plugin).
954957

955958
**webpack.config.js**
956959

@@ -981,9 +984,11 @@ module.exports = {
981984
};
982985
```
983986

987+
> 💡 Use this setup to extract and cache CSS in production while keeping fast style injection during development.
988+
984989
### Emit assets
985990

986-
To write a asset from PostCSS plugin to the webpack, need to add a message in `result.messages`.
991+
To emit an asset from PostCSS plugin to the webpack, need to add a message in `result.messages`.
987992

988993
The message should contain the following fields:
989994

@@ -1032,6 +1037,8 @@ module.exports = {
10321037
};
10331038
```
10341039

1040+
> ℹ️ This allows your plugin to generate additional files as part of the build process, and Webpack will handle them like any other emitted asset.
1041+
10351042
### Add dependencies, contextDependencies, buildDependencies, missingDependencies
10361043

10371044
The dependencies are necessary for webpack to understand when it needs to run recompilation on the changed files.
@@ -1085,9 +1092,9 @@ module.exports = {
10851092
};
10861093
```
10871094

1088-
Or you can use ready-made plugin [postcss-add-dependencies](https://www.npmjs.com/package/postcss-add-dependencies).
1095+
> 💡 You can use ready-made plugin [postcss-add-dependencies](https://www.npmjs.com/package/postcss-add-dependencies) to simplify this process.
10891096
1090-
2. Pass `loaderContext` in plugin.
1097+
2. Pass `loaderContext` in plugin (for advanced setups).
10911098

10921099
**webpack.config.js**
10931100

@@ -1117,8 +1124,12 @@ module.exports = {
11171124
};
11181125
```
11191126

1127+
> ⚠️ Use this approach only when managing dependencies via custom PostCSS configurations with dynamic imports or external files.
1128+
11201129
**postcss.config.js**
11211130

1131+
Pass the `webpackLoaderContext` through the PostCSS `api` object:
1132+
11221133
```js
11231134
module.exports = (api) => ({
11241135
plugins: [
@@ -1131,6 +1142,8 @@ module.exports = (api) => ({
11311142

11321143
**postcssCustomPlugin.js**
11331144

1145+
Register a file dependency using `loaderContext.addDependency`:
1146+
11341147
```js
11351148
const path = require("path");
11361149

@@ -1149,9 +1162,12 @@ postcssCustomPlugin.postcss = true;
11491162
module.exports = postcssCustomPlugin;
11501163
```
11511164

1165+
> ✅ 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+
11521167
## Contributing
11531168

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.
11551171

11561172
[CONTRIBUTING](./.github/CONTRIBUTING.md)
11571173

0 commit comments

Comments
 (0)