@@ -188,12 +188,19 @@ module.exports = {
188188### ` minify `
189189
190190Type: ` Function|Array<Function> `
191- Default: ` undefined `
191+ Default: ` CssMinimizerPlugin.cssnanoMinify `
192192
193- Allows you to override default minify function.
193+ Allows to override default minify function.
194194By default plugin uses [ cssnano] ( https://github.com/cssnano/cssnano ) package.
195195Useful for using and testing unpublished versions or forks.
196196
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+
197204> ⚠️ ** Always use ` require ` inside ` minify ` function when ` parallel ` option enabled** .
198205
199206#### ` Function `
@@ -206,36 +213,14 @@ module.exports = {
206213 minimize: true ,
207214 minimizer: [
208215 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' ,
226220 },
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+ },
238222 },
223+ minify: CssMinimizerPlugin .cleanCssMinify ,
239224 }),
240225 ],
241226 },
@@ -247,6 +232,37 @@ module.exports = {
247232If an array of functions is passed to the ` minify ` option, the ` minimizerOptions ` must also be an array.
248233The function index in the ` minify ` array corresponds to the options object with the same index in the ` minimizerOptions ` array.
249234
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+
250266### ` minimizerOptions `
251267
252268Type: ` Object|Array<Object> `
0 commit comments