A
A
Alexon Classic2018-09-23 04:32:19
gulp.js
Alexon Classic, 2018-09-23 04:32:19

How to use Gupl-cssnano presets (newbie question)?

Hello!
Just started to learn Gupl and faced the need:

  • minify final CSS file;
  • remove (combine) duplicates in it
  • set vendor prefixes for css properties (it is clear that Gulp-Autoprefixer is responsible for this)
  • delete comments
  • well, and everything else (so as not to paint a lot) that is needed for a normal final CSS file...

I rummaged through a bunch of information on the Internet, got acquainted with such plugins as: gulp-clean-css , gulp-csso , gulp-css-purge and of course gulp -cssnano itself ... I
opted for the last one - gulp-cssnano because .he has a lot of presets .
But! How to use them, at the office. I did not find the site (as well as on the Internet), except for one - discardOverridden: {removeAll: false}...
Tried by analogy:
.pipe(cssnano({
  autoprefixer: {browsers: supported, add: true, cascade: false, grid: true}, //работает. Остальное - нет
  discardOverridden: {removeAll: false},
  cssDeclarationSorter: {order: 'smacss'},
  //discardComments: {removeAll: false},
  discardComments: false,
  cssDeclarationSorter: false,
  mergeIdents: true
}))

but cssnano:
  1. removes all media - (discardOverridden)
  2. does not sort - (cssDeclarationSorter)
  3. if I have several different classes with the same styles like:
    .popover-title, .popover-content{
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif
    }

    and
    body, label, select, input[type=text], textarea{
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif
    }

    then cssnano doesn't merge them together... For example like this:
    body, label, select, input[type=text], textarea, .popover-title, .popover-content{
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif
    }

In a word: plz tell me how to use it (if possible with examples)?
Unfortunately, my English is sooooo bad, but from what I could read, the thought creeps in on me that cssnano needs to be used with gulp-postcss ... or is it not necessary?
Thanks in advance for your replies !

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Balya, 2018-10-17
@Balya

CSSnano works dozens of times slower and is not the best choice in other respects. Use CSSO or gulp-clean-css with default settings - that's enough if you don't want to mess around with settings.

A
Andrey Yugay, 2020-07-12
@mcmimik

If you are using version 4 of cssnano, try specifying both preset and your options. For example:

.pipe(cssnano(['default', {
  cssDeclarationSorter: false,
  discardOverridden: false,
  discardComments: false,
  mergeIdents: true
}]))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question