@@ -188,12 +188,19 @@ module.exports = {
188
188
### ` minify `
189
189
190
190
Type: ` Function|Array<Function> `
191
- Default: ` undefined `
191
+ Default: ` CssMinimizerPlugin.cssnanoMinify `
192
192
193
- Allows you to override default minify function.
193
+ Allows to override default minify function.
194
194
By default plugin uses [ cssnano] ( https://github.com/cssnano/cssnano ) package.
195
195
Useful for using and testing unpublished versions or forks.
196
196
197
+ Possible options:
198
+
199
+ - CssMinimizerPlugin.cssnanoMinify
200
+ - CssMinimizerPlugin.cssoMinify
201
+ - CssMinimizerPlugin.cleanCssMinify
202
+ - async (data, inputMap, minimizerOptions) => {return {code: ` a{color: red} ` , map: ` ... ` , warnings: [ ] }}
203
+
197
204
> ⚠️ ** Always use ` require ` inside ` minify ` function when ` parallel ` option enabled** .
198
205
199
206
#### ` Function `
@@ -206,36 +213,14 @@ module.exports = {
206
213
minimize: true ,
207
214
minimizer: [
208
215
new CssMinimizerPlugin ({
209
- minify : (data , inputMap , minimizerOptions ) => {
210
- const postcss = require (' postcss' );
211
-
212
- const plugin = postcss .plugin (
213
- ' custom-plugin' ,
214
- () => (css , result ) => {
215
- // custom code
216
- }
217
- );
218
-
219
- const [[filename , input ]] = Object .entries (data);
220
-
221
- const postcssOptions = {
222
- from: filename,
223
- to: filename,
224
- map: {
225
- prev: inputMap,
216
+ minimizerOptions: {
217
+ level: {
218
+ 1 : {
219
+ roundingPrecision: ' all=3,px=5' ,
226
220
},
227
- };
228
-
229
- return postcss ([plugin])
230
- .process (input, postcssOptions)
231
- .then ((result ) => {
232
- return {
233
- code: result .css ,
234
- map: result .map ,
235
- warnings: result .warnings (),
236
- };
237
- });
221
+ },
238
222
},
223
+ minify: CssMinimizerPlugin .cleanCssMinify ,
239
224
}),
240
225
],
241
226
},
@@ -247,6 +232,37 @@ module.exports = {
247
232
If an array of functions is passed to the ` minify ` option, the ` minimizerOptions ` must also be an array.
248
233
The function index in the ` minify ` array corresponds to the options object with the same index in the ` minimizerOptions ` array.
249
234
235
+ ** webpack.config.js**
236
+
237
+ ``` js
238
+ module .exports = {
239
+ optimization: {
240
+ minimize: true ,
241
+ minimizer: [
242
+ new CssMinimizerPlugin ({
243
+ minimizerOptions: [
244
+ {}, // Options for the first function (CssMinimizerPlugin.cssnanoMinify)
245
+ {}, // Options for the second function (CssMinimizerPlugin.cleanCssMinify)
246
+ {}, // Options for the third function
247
+ ],
248
+ minify: [
249
+ CssMinimizerPlugin .cssnanoMinify ,
250
+ CssMinimizerPlugin .cleanCssMinify ,
251
+ async (data , inputMap , minimizerOptions ) => {
252
+ // To do something
253
+ return {
254
+ code: ` a{color: red}` ,
255
+ map: ` {"version": "3", ...}` ,
256
+ warnings: [],
257
+ };
258
+ },
259
+ ],
260
+ }),
261
+ ],
262
+ },
263
+ };
264
+ ```
265
+
250
266
### ` minimizerOptions `
251
267
252
268
Type: ` Object|Array<Object> `
0 commit comments