diff --git a/src/transforms/postcss.js b/src/transforms/postcss.js index 90898e807d6..370935674c3 100644 --- a/src/transforms/postcss.js +++ b/src/transforms/postcss.js @@ -1,7 +1,7 @@ const localRequire = require('../utils/localRequire'); const loadPlugins = require('../utils/loadPlugins'); const postcss = require('postcss'); -const cssnano = require('cssnano'); +const semver = require('semver'); module.exports = async function(asset) { let config = await getConfig(asset); @@ -49,14 +49,18 @@ async function getConfig(asset) { } if (asset.options.minify) { + let [cssnano, {version}] = await Promise.all( + ['cssnano', 'cssnano/package.json'].map(name => + localRequire(name, asset.name).catch(() => require(name)) + ) + ); config.plugins.push( cssnano( (await asset.getConfig(['cssnano.config.js'])) || { - // Only enable safe css transforms by default. + // Only enable safe css transforms if cssnano < 4 // See: https://github.com/parcel-bundler/parcel/issues/698 - // Note: Remove when upgrading cssnano to v4 // See: https://github.com/ben-eb/cssnano/releases/tag/v4.0.0-rc.0 - safe: true + safe: semver.satisfies(version, '<4.0.0-rc') } ) );