| |
|
|
| |
| |
| |
| |
|
|
| const createSimplePreset = require('./cssnano-preset-simple') |
|
|
| module.exports = (opts = {}, postcss = require('postcss')) => { |
| const excludeAll = Boolean(opts && opts.excludeAll) |
|
|
| const userOpts = Object.assign({}, opts) |
|
|
| if (excludeAll) { |
| for (const userOption in userOpts) { |
| if (!userOpts.hasOwnProperty(userOption)) continue |
| const val = userOpts[userOption] |
| if (!Boolean(val)) { |
| continue |
| } |
|
|
| if (Object.prototype.toString.call(val) === '[object Object]') { |
| userOpts[userOption] = Object.assign({}, { exclude: false }, val) |
| } |
| } |
| } |
|
|
| const options = Object.assign( |
| {}, |
| excludeAll ? { rawCache: true } : undefined, |
| userOpts |
| ) |
|
|
| const plugins = [] |
| createSimplePreset(options).plugins.forEach((plugin) => { |
| if (Array.isArray(plugin)) { |
| let [processor, pluginOpts] = plugin |
| processor = processor.default || processor |
|
|
| const isEnabled = |
| |
| (!excludeAll && typeof pluginOpts === 'undefined') || |
| |
| (typeof pluginOpts === 'boolean' && pluginOpts) || |
| |
| (!excludeAll && |
| pluginOpts && |
| typeof pluginOpts === 'object' && |
| !pluginOpts.exclude) || |
| |
| (excludeAll && |
| pluginOpts && |
| typeof pluginOpts === 'object' && |
| pluginOpts.exclude === false) |
|
|
| if (isEnabled) { |
| plugins.push(processor(pluginOpts)) |
| } |
| } else { |
| plugins.push(plugin) |
| } |
| }) |
|
|
| return postcss(plugins) |
| } |
|
|
| module.exports.postcss = true |
|
|