配置文件
cssnano
config files
We use configuration for cssnano
using file name as cssnano.config.js
, cssnano
property in your package.json
, using cssnano.config.json
and .cssnanorc
as well.
We are using cosmiconfig
in order to load cssnano config. Please read here for more details
Options
preset
- Type:
string
|function
|[string, Objects<preset options here>]
|[function(preset options here)]
For
string
, the name should be of typecssnano-preset-<name>
and you need to usename
alone eg :preset : ['default', {}]
Contains lists of postcss
plugins where each plugin does their own minification.
Example:
// cssnano.config.jsmodule.exports = {preset: [require('cssnano-preset-default')]// orpreset: require('cssnano-preset-default')// orpreset: ['advanced', { discardComments: false }]// orpreset: [require('cssnano-preset-default'), {discardComments: false}]}
plugins
- Type:
Array<'string' | 'function' | ['string' | 'function', Object<Options for the plugin here>]>
If you want to pass config to the plugin, you need to use Array's of array for the plugins i.e
plugins: [ ['autoprefixer', {}] ]
These plugins will run after once all presets operations are complete.
Example:
// cssnano.config.jsmodule.exports = {plugins: [require('autoprefixer')]// orplugins: ['autoprefixer', 'postcss-preset-env']// orplugins: [['autoprefixer', { remove: false },]// orplugins: [[ require('autoprefixer'), {remove: false} ],[ 'postcss-preset-env']]}
Alternatives
You can use the postcss
config file and both preset
and plugins
will be passed as the options for cssnano
.
Refer here for more details.