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
Copy file name to clipboardExpand all lines: README.md
+50-49Lines changed: 50 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@
15
15
16
16
This plugin uses [cssnano](https://cssnano.github.io/cssnano/) to optimize and minify your CSS.
17
17
18
-
Just like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin) but more accurate with source maps and assets using query string, allows caching and works in parallel mode.
18
+
It serves as a more accurate alternative to [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin), with better support for source maps, assets with query strings, caching, and parallel processing.
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
60
-
// `...`,
59
+
// For webpack v5, you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line // `...`,
61
60
newCssMinimizerPlugin(),
62
61
],
63
62
},
64
63
plugins: [newMiniCssExtractPlugin()],
65
64
};
66
65
```
67
66
68
-
This will enable CSS optimization only in production mode.
67
+
> [!NOTE]
68
+
>
69
+
> This enables CSS optimization only in production mode by default.
69
70
70
-
If you want to run it also in development set the `optimization.minimize` option to `true`:
71
+
To enable it in development mode as well, set the `optimization.minimize` option to `true`:
71
72
72
73
**webpack.config.js**
73
74
@@ -81,20 +82,20 @@ module.exports = {
81
82
};
82
83
```
83
84
84
-
And run `webpack` via your preferred method.
85
+
Finally, run Webpack using your preferred method.
85
86
86
87
## Note about source maps
87
88
88
-
**Works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
89
+
**This plugin works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/devtool/) option.**
89
90
90
91
Why? Because CSS support only these source map types.
91
92
92
-
The plugin respect the [`devtool`](https://webpack.js.org/configuration/devtool/) and using the `SourceMapDevToolPlugin`plugin.
93
-
Using supported `devtool`values enable source map generation.
94
-
Using `SourceMapDevToolPlugin` with enabled the `columns` option enables source map generation.
93
+
The plugin respects the [`devtool`](https://webpack.js.org/configuration/devtool/)setting and uses the `SourceMapDevToolPlugin`internally.
94
+
Using a supported `devtool`value enables source map generation.
95
+
Enabling the `columns` option in `SourceMapDevToolPlugin` also allows source map generation.
95
96
96
-
Use source maps to map error message locations to modules (this slows down the compilation).
97
-
If you use your own `minify` function please read the `minify` section for handling source maps correctly.
97
+
Use source maps to map error message locations to their original modules (note that this may slow down compilation).
98
+
If you use your own `minify` function please refer to the `minify` section for correct handling of source maps.
98
99
99
100
## Options
100
101
@@ -103,14 +104,15 @@ If you use your own `minify` function please read the `minify` section for handl
103
104
|**[`test`](#test)**|`String\|RegExp\|Array<String\|RegExp>`|`/\.css(\?.*)?$/i`| Test to match files against. |
104
105
|**[`include`](#include)**|`String\|RegExp\|Array<String\|RegExp>`|`undefined`| Files to include. |
105
106
|**[`exclude`](#exclude)**|`String\|RegExp\|Array<String\|RegExp>`|`undefined`| Files to exclude. |
Use multi-process parallel running to improve the build speed.
180
-
Default number of concurrent runs: `os.cpus().length - 1` or `os.availableParallelism() - 1` (if this function is supported).
182
+
The default number of concurrent runs: `os.cpus().length - 1` or `os.availableParallelism() - 1` (if this function is supported).
181
183
182
184
> ℹ️ Parallelization can speed up your build significantly and is therefore **highly recommended**.
183
185
> If a parallelization is enabled, the packages in `minimizerOptions` must be required via strings (`packageName` or `require.resolve(packageName)`). Read more in [`minimizerOptions`](#minimizeroptions)
184
186
185
187
#### `Boolean`
186
188
187
-
Enable/disable multi-process parallel running.
189
+
Enable or disable multi-process parallel running.
188
190
189
191
**webpack.config.js**
190
192
@@ -203,7 +205,7 @@ module.exports = {
203
205
204
206
#### `Number`
205
207
206
-
Enable multi-process parallel running and set number of concurrent runs.
208
+
Enable multi-process parallel running and specify the number of concurrent runs.
207
209
208
210
**webpack.config.js**
209
211
@@ -222,12 +224,12 @@ module.exports = {
222
224
223
225
### `minify`
224
226
225
-
Type: `Function|Array<Function>`
226
-
Default: `CssMinimizerPlugin.cssnanoMinify`
227
+
-Type: `Function|Array<Function>`
228
+
-Default: `CssMinimizerPlugin.cssnanoMinify`
227
229
228
-
Allows overriding default minify function.
230
+
Overrides the default minify function.
229
231
By default, plugin uses [cssnano](https://github.com/cssnano/cssnano) package.
230
-
Useful for using and testing unpublished versions or forks.
232
+
This is useful when using or testing unpublished versions or forks.
231
233
232
234
Possible options:
233
235
@@ -240,7 +242,7 @@ Possible options:
240
242
241
243
> [!WARNING]
242
244
>
243
-
> **Always use `require` inside `minify` function when `parallel` option enabled**.
245
+
> **Always use `require` inside `minify` function when `parallel` option is enabled**.
The function index in the `minify` array corresponds to the options object with the same index in the `minimizerOptions` array.
338
340
If you use `minimizerOptions` like object, all `minify` function accept it.
339
341
340
-
> If a parallelization is enabled, the packages in `minimizerOptions` must be required via strings (`packageName` or `require.resolve(packageName)`). In this case, we shouldn't use `require`/`import`.
342
+
> If parallelization is enabled, the packages in `minimizerOptions` must be referenced via strings (`packageName` or `require.resolve(packageName)`). In this case, we shouldn't use `require`/`import`.
341
343
342
344
```js
343
345
module.exports= {
@@ -356,15 +358,15 @@ module.exports = {
356
358
357
359
##### `processorOptions` (⚠ only cssnano)
358
360
359
-
Type: `Object`
360
-
Default: `{ from: assetName }`
361
+
-Type: `Object`
362
+
-Default: `{ from: assetName }`
361
363
362
364
Allows filtering options [`processoptions`](https://postcss.org/api/#processoptions) for the cssnano.
363
365
The `parser`,` stringifier` and `syntax` can be either a function or a string indicating the module that will be imported.
364
366
365
367
> [!WARNING]
366
368
>
367
-
> **If a function is passed, the `parallel` option must be disabled.**.
369
+
> **If any of these options are passed as a function, the `parallel` option must be disabled.**.
0 commit comments