I'm executing the following line to compress a less file:
lessc -x site.less site.css
And all my CSS blocks comment /*foo */
are removed.
It is possible to compress my less files and keep the comments?
Update: Currently SimpLESS do it as of version 1.4, the change log said:
if a LESS file starts with a CSS block comment, SimpLESS will keep that comment after minification (i.e. for Wordpress)
I would like to know if is it possible to do it with lessc
command.
If you want to keep comments in compiled LESS files, you should be using block comments for non-minified code:
site.css/* this is a keeper */
.foo {
...
}
And for minified code you should use --yui-compress
with /*!
to start your comments:
/*! this is a keeper */
.foo{...}
This is because the lessc
command with the --yui-compress
flag pipes the CSS through YUI Compressor, and YUI Compressor allows comments when they begin with /*!
.
If you're using a relatively recent version of lessc then simply start the block comment with the /*!
comment syntax.
eg
/*! This is preserved */
Previously you needed to use --yui-compress to get this to work, it now works by default.
The yui-compress
option was removed a while ago (I haven't found the exact commit yet, but it was removed before November 2013).
This comment syntax also works with wordpress themes so you can preserve wordpress comment based meta data this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With