Skip to content

Commit 5c141d8

Browse files
tommytroylinNMFR
authored andcommitted
add a plugin option to support passing options cssnano v4 (NMFR#73)
* pass cssNanoOptions to cssnano * update doc for cssProcessorPluginOptions * change cssNanoOptions to cssProcessorPluginOptions
1 parent 44d5291 commit 5c141d8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The plugin can receive the following options (all of them are optional):
2525
* assetNameRegExp: A regular expression that indicates the names of the assets that should be optimized \ minimized. The regular expression provided is run against the filenames of the files exported by the ExtractTextPlugin instances in your configuration, not the filenames of your source CSS files. Defaults to `/\.css$/g`
2626
* cssProcessor: The CSS processor used to optimize \ minimize the CSS, defaults to [cssnano](http://github.com/ben-eb/cssnano). This should be a function that follows cssnano.process interface (receives a CSS and options parameters and returns a Promise).
2727
* cssProcessorOptions: The options passed to the cssProcessor, defaults to `{}`
28+
* cssProcessorPluginOptions: The plugin options passed to the cssProcessor, defaults to `{}`
2829
* canPrint: A boolean indicating if the plugin can print messages to the console, defaults to `true`
2930

3031
## Example:
@@ -45,7 +46,9 @@ module.exports = {
4546
new OptimizeCssAssetsPlugin({
4647
assetNameRegExp: /\.optimize\.css$/g,
4748
cssProcessor: require('cssnano'),
48-
cssProcessorOptions: { discardComments: { removeAll: true } },
49+
cssProcessorPluginOptions: {
50+
preset: ['default', { discardComments: { removeAll: true } }],
51+
},
4952
canPrint: true
5053
})
5154
]

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class OptimizeCssAssetsWebpackPlugin extends LastCallWebpackPlugin {
2323
this.options.cssProcessorOptions = !options || options.cssProcessorOptions === undefined ?
2424
{} :
2525
options.cssProcessorOptions;
26+
this.options.cssProcessorPluginOptions = !options || options.cssProcessorPluginOptions === undefined ?
27+
{} :
28+
options.cssProcessorPluginOptions;
2629
}
2730

2831
buildPluginDescriptor() {
@@ -59,7 +62,7 @@ class OptimizeCssAssetsWebpackPlugin extends LastCallWebpackPlugin {
5962
}
6063
}
6164
return this.options
62-
.cssProcessor.process(css.source, processOptions)
65+
.cssProcessor.process(css.source, processOptions, this.options.cssProcessorPluginOptions)
6366
.then(r => {
6467
if (processOptions.map && r.map && r.map.toString) {
6568
assets.setAsset(assetName + '.map', r.map.toString());

0 commit comments

Comments
 (0)