Skip to content

Commit

Permalink
add a plugin option to support passing options cssnano v4 (#73)
Browse files Browse the repository at this point in the history
* pass cssNanoOptions to cssnano

* update doc for cssProcessorPluginOptions

* change cssNanoOptions to cssProcessorPluginOptions
  • Loading branch information
tommytroylin authored and NMFR committed Aug 29, 2018
1 parent 44d5291 commit 5c141d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The plugin can receive the following options (all of them are optional):
* 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`
* 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).
* cssProcessorOptions: The options passed to the cssProcessor, defaults to `{}`
* cssProcessorPluginOptions: The plugin options passed to the cssProcessor, defaults to `{}`
* canPrint: A boolean indicating if the plugin can print messages to the console, defaults to `true`

## Example:
Expand All @@ -45,7 +46,9 @@ module.exports = {
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.optimize\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComments: { removeAll: true } },
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }],
},
canPrint: true
})
]
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class OptimizeCssAssetsWebpackPlugin extends LastCallWebpackPlugin {
this.options.cssProcessorOptions = !options || options.cssProcessorOptions === undefined ?
{} :
options.cssProcessorOptions;
this.options.cssProcessorPluginOptions = !options || options.cssProcessorPluginOptions === undefined ?
{} :
options.cssProcessorPluginOptions;
}

buildPluginDescriptor() {
Expand Down Expand Up @@ -59,7 +62,7 @@ class OptimizeCssAssetsWebpackPlugin extends LastCallWebpackPlugin {
}
}
return this.options
.cssProcessor.process(css.source, processOptions)
.cssProcessor.process(css.source, processOptions, this.options.cssProcessorPluginOptions)
.then(r => {
if (processOptions.map && r.map && r.map.toString) {
assets.setAsset(assetName + '.map', r.map.toString());
Expand Down

0 comments on commit 5c141d8

Please sign in to comment.