1

I found this answer about how to compile the less files, optimizing (-O2) and compressing (-x) them:

lessc -x -O2 path/to/assets/main.less > path/to/output.css

I installed less globally (npm install -g less), but it seems that -O2 is not interpreted like expected:

Unable to interpret argument O2 - if it is a plugin (less-plugin-O2), make sure that it is installed under or at the same level as less

How can I fix this error?

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • Is that a zero, `0`, or an upper-case letter, `O`? – Sparky Jan 13 '15 at 15:52
  • @Sparky It's letter, `O`... – Ionică Bizău Jan 13 '15 at 15:55
  • That seems to be a very old answer mate and Less has undergone a lot of revisions post it, so I doubt if that particular option got dropped (or) was replaced. – Harry Jan 13 '15 at 16:35
  • 1
    @Harry I also think that it was deprecated, but finding the replacement for that would be great. – Ionică Bizău Jan 13 '15 at 16:43
  • @IonicăBizău: Yup trying mate. The comment by Zack (to shakaran's answer) in [this](http://stackoverflow.com/questions/5691173/how-do-i-compile-a-directory-full-of-less-css-files-to-css) thread kind of confirms the assumption that it was deprecated. – Harry Jan 13 '15 at 16:54

2 Answers2

3

What exactly do you expect from that -02 option? It is not available in the latest versions of Less any more.

From Less v1.5:

-------------------------- Deprecated ----------------
-O0, -O1, -O2 Set the parser's optimization level. The lower the number, the less nodes it will create in the tree. This could matter for debugging, or if you want to access the individual nodes in the tree.

-

I expect that if I do: h1 { font-weight: 300; } h2 { font-weight: 300; }, then, after compilation, I have: h1, h2 { font-weight: 300; }. That's why I understood that -O2 was doing. Is there any replacement for that?

I wonder if -O2 indeed did that. But clean-css does what you are asking.

You could try https://github.com/less/less-plugin-clean-css with the advanced option turned on.

Run npm install less-plugin-clean-css after that you can use lessc file.less --clean-css="advanced".

echo "h1 { font-weight: 300; } h2 { font-weight: 300; }" | lessc --clean-css="advanced" -

outputs into the console:

h1,h2{font-weight:300}

See also: How to keep duplicate properties in compiled CSS file when use LESS?

Since version 2 of Less writing your own plugin is easy, see: http://lesscss.org/usage/#plugins-for-plugin-authors. You can write a plugin for any postprocess such compressing, minifying and so on, other examples: https://github.com/less/less-plugin-autoprefix, https://github.com/bassjobsen/less-plugin-pleeease.

Community
  • 1
  • 1
Bass Jobsen
  • 48,736
  • 16
  • 143
  • 224
  • I expect that if I do: `h1 { font-weight: 300; } h2 { font-weight: 300; }`, then, after compilation, I have: `h1, h2 { font-weight: 300; }`. That's why I understood that `-O2` was doing. Is there any replacement for that? – Ionică Bizău Jan 14 '15 at 05:58
0

You can install older version

npm install less@1.5 -g

It is solution for using in Eclipse 4.4.2 fo r Windows.

Pažout
  • 2,061
  • 20
  • 10
  • `O` option had no effect a while before `1.5` (Actually I doubt it ever had any effect since the very first JS version. Most likely this was just an overlooked left-over from the original Ruby version (and even there it was just about internal AST representation not affecting the generated CSS in any way)). – seven-phases-max May 04 '15 at 16:29