Skip to content

Commit 45dd784

Browse files
feat: added defaults functions for clean-css and csso
1 parent 91f9977 commit 45dd784

File tree

7 files changed

+308
-2191
lines changed

7 files changed

+308
-2191
lines changed

README.md

+41-3
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,19 @@ module.exports = {
188188
### `minify`
189189

190190
Type: `Function|Array<Function>`
191-
Default: `undefined`
191+
Default: `CssMinimizerPlugin.cssnano`
192192

193-
Allows you to override default minify function.
193+
Allows to override default minify function.
194194
By default plugin uses [cssnano](https://github.com/cssnano/cssnano) package.
195195
Useful for using and testing unpublished versions or forks.
196196

197+
Possible options:
198+
199+
- CssMinimizerPlugin.cssnano
200+
- CssMinimizerPlugin.csso
201+
- CssMinimizerPlugin.cleanCss
202+
- async (data, inputMap, minimizerOptions) => {return {code: `a{color: red}`, map: `...`, warnings: []}}
203+
197204
> ⚠️ **Always use `require` inside `minify` function when `parallel` option enabled**.
198205
199206
#### `Function`
@@ -230,7 +237,7 @@ module.exports = {
230237
.process(input, postcssOptions)
231238
.then((result) => {
232239
return {
233-
css: result.css,
240+
code: result.css,
234241
map: result.map,
235242
warnings: result.warnings(),
236243
};
@@ -247,6 +254,37 @@ module.exports = {
247254
If an array of functions is passed to the `minify` option, the `minimizerOptions` must also be an array.
248255
The function index in the `minify` array corresponds to the options object with the same index in the `minimizerOptions` array.
249256

257+
**webpack.config.js**
258+
259+
```js
260+
module.exports = {
261+
optimization: {
262+
minimize: true,
263+
minimizer: [
264+
new CssMinimizerPlugin({
265+
minimizerOptions: [
266+
{}, // Options for the first function (CssMinimizerPlugin.cssnano)
267+
{}, // Options for the second function (CssMinimizerPlugin.cssClean)
268+
{}, // Options for the third function
269+
],
270+
minify: [
271+
CssMinimizerPlugin.cssnano,
272+
CssMinimizerPlugin.cssClean,
273+
async (data, inputMap, minimizerOptions) => {
274+
// To do something
275+
return {
276+
code: `a{color: red}`,
277+
map: `{"version": "3", ...}`,
278+
warnings: [],
279+
};
280+
},
281+
],
282+
}),
283+
],
284+
},
285+
};
286+
```
287+
250288
### `minimizerOptions`
251289

252290
Type: `Object|Array<Object>`

0 commit comments

Comments
 (0)