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.