Since version 4 has been in-development for some time, we thought it would be
best to release an alpha version so that we could catch any issues before
the actual release.
Breaking changes
-
cssnano & its plugins have been upgraded to PostCSS 6.x. Please ensure that
for optimal results that you use cssnano with a PostCSS 6 compatible runner
& that any other plugins are also using PostCSS 6. -
cssnano is now essentially a preset loader and does not contain any built-in
transforms (instead, it delegates tocssnano-preset-default
by default).
Due to the new architecture, it's not possible to exclude asynchronous
transforms and run it synchronously, unlike in 3.x. Any transforms that
were "core" modules have now been extracted out into separate packages. -
Because of the new preset system, cssnano will not accept any transformation
options; these must be set in the preset. The option names remain mostly the
same, except some cases where "core" modules have been extracted out:core
is nownormalizeWhitespace
.reduceBackgroundRepeat
is nownormalizeRepeatStyle
.reduceDisplayValues
is nownormalizeDisplayValues
.reducePositions
is nownormalizePositions
.reduceTimingFunctions
is nownormalizeTimingFunctions
.styleCache
is nowrawCache
.
When excluding transforms, we now have an
exclude
option (in 3.x this was
nameddisable
). Similarly, thesafe
option was removed; the defaults
are now much less aggressive. -
By default, the following transforms are no longer applied to any input CSS.
You may see an increased output file size as a result:autoprefixer
postcss-discard-unused
postcss-merge-idents
postcss-reduce-idents
postcss-zindex
Note that you can load
cssnano-preset-advanced
instead which does contain
these transforms. -
We no longer detect previous plugins to silently exclude our own, and now
consider this to be an anti-pattern. Sopostcss-filter-plugins
was removed. -
We also changed some options to make the default transforms safer:
postcss-minify-font-values
:removeAfterKeyword
set tofalse
fromtrue
.postcss-normalize-url
:stripWWW
set tofalse
fromtrue
.
-
cssnano now does not accept the
sourcemap
shortcut option; please refer
to the PostCSS documentation on sourcemaps. Thequickstart.js
file included
with this module will give you a good starting point. -
cssnano.process
is no longer a custom method; we use the built-inprocess
method exposed on each PostCSS plugin. The new signature is
cssnano.process(css, postcssOpts, cssnanoOpts)
, in 3.x it was
cssnano.process(css, cssnanoOpts)
. -
We dropped support for Node 0.12, now requiring at least Node 4.
-
Finally, cssnano is now developed as a monorepo, due to the fact that some
transforms have a lot of grey area/overlap. Due to this, some modules have
been refactored to delegate responsibility to others, such that duplication
of functionality is minimized. For instance,postcss-colormin
will no
longer compress whitespace or compress numbers, as those are handled by
postcss-normalize-whitespace
&postcss-convert-values
respectively.
Other changes
- Due to the PostCSS 6 upgrade, we have been able to reduce usage of custom
methods, such as nodeclone
behaviour. In cases where some utility
has been used by several plugins it is now a separate package, reducing
cssnano's footprint. - cssnano now makes much better use of Browserslist.
postcss-colormin
&
postcss-reduce-initial
were enhanced with different behaviour depending
on which browsers are passed. And now, the footprint for thecaniuse-db
dependency is much smaller thanks tocaniuse-lite
- 7 times smaller as
of this writing. This makes cssnano much faster to download from npm!