22

Is it possible to get minified compiled CSS from LESS automatically? Every time I change something, I have to manually compress it.

I use less.js to compile LESS.

Thanks.

Dan Homola
  • 3,819
  • 1
  • 28
  • 43
Jay
  • 405
  • 1
  • 3
  • 12
  • 3
    If you're using the Less compiler, in order to output minified CSS, pass the `-x` option. This is documented: http://lesscss.org/#using-less-command-line-usage – Hashem Qolami Aug 30 '14 at 07:11
  • 2
    @HashemQolami you should make this an answer. – Pavlo Aug 30 '14 at 07:14
  • Many IDEs have plugin that does LESS compilation and CSS minification automatically. E.g. Web Essentials in VS 2012 or above. Not sure if it's useful since you didn't mention what environment you're using. – kevin Aug 30 '14 at 07:16

3 Answers3

29

$ lessc styles.less -x The compress command has been deprecated.

you'll have to use this command $ lessc -clean-css style.less style.min.css

before use above command you've to install less-plugin-clean-css using below command

$ npm install less-plugin-clean-css -g
Hidayt Rahman
  • 2,490
  • 26
  • 32
20

If you are using the Less command-line compiler, you could pass the -x option in order to output minified CSS.

$ lessc styles.less -x

This is documented in Less doc:

To output minified CSS, simply pass the -x option. If you would like more involved minification, the Clean CSS is also available with the --clean-css option.

To see all the command line options run lessc without parameters.

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
  • Actually, I use less.js to compile LESS. – Jay Aug 30 '14 at 07:18
  • 4
    @Jay Less.js does all the things in front-end side, therefore minifying the output doesn't make sense. – Hashem Qolami Aug 30 '14 at 07:20
  • Oh. So Hashem can you suggest a way where I can make website more fast with minified output? Sorry for the same question. Getting confused. – Jay Aug 30 '14 at 07:33
  • 5
    IMHO If you really care about the performance, it's better to compile Less files and compress the output on your local system, Then `` the minified version of the output (which is CSS) into your HTML pages. – Hashem Qolami Aug 30 '14 at 07:40
  • 4
    `-x` is presently deprecated – James Perih Nov 01 '18 at 20:52
9

According to github README.md for minification you should use this command:

lessc file.less --clean-css="--s1 --advanced --compatibility=ie8"