Search code examples
cssless

lessc: Does anyone have experience with the Mac command line?


Perhaps all I need is a link to some meaningful documentation or to a tutorial about lessc, but I was wondering whether someone (with more less experience than I have) could explain a few things to me?

On my Mac, I have all the tools available, so I can check whether lessc is available on my machine, simply by typing:

lessc

Then I press ENTER and I get the lessc help file. The help file consists of 21 lines of explanations. Those explanations are rather terse, and I can't find answers to all my 'lessc questions. So there is insufficient information (for me), and I could not find any more explanations anywhere else. Still, I think I have a basic and working way of concatenating, minifying and compiling my LESS source files into a single CSS file, like so:

lessc --strict-imports --verbose --yui-compress new.less newstyles.css

Again, this is on a Mac (Linux), and although it seems to work, I guess I would like to know whether I'm doing it right?

There are a couple of explanations in the lessc help file that don't make sense to me, and perhaps I'm missing out on some advanced functionality.

What does this mean, exactly? (Please forgive me for asking such a silly question, but when it comes to the command line, I'm still a newbie.)

If source is set to `-' (dash or hyphen-minus), input is read from stdin.

What does this allow me to do?

--include-path

Does that mean if I add one or more directory location, that `lessc' will look in all of those directories for my LESS files? And, if so, is that actually necessary, if my LESS source file contains nothing but includes, pointing to the individual LESS source files I want to combine into one CSS files?

Or is there another use for this directive that might help me be more effective?

Then there are the two compress directives. The first one is --compress and the second one is --yui-compress. Does the first one just minify the CSS output? Does the YUI option compress and minify the CSS output?

And although I'm successfully using --yui-compress in my little build process, I am not sure whether that is actually working or whether I am just fooling myself? The explanation in the lessc help file states:

Compress output using cssmin.js.

Do I already have cssmin.js anywhere? If so, does lessc auto-magically know where to find it? I have searched my entire machine for this file, but it doesn't exist anywhere. What's the proper way to use the --yui-compress directive then? Do I need to install the YUI Compressor or anything else somewhere?

Parser Optimization Level? All it says is that:

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.

So is -00 the maximum optimization, if I don't care about how dense and cryptic my CSS might look in the end?

If necessary, please do teach me a thing or two and point me to any previously asked questions that would answer my questions about lessc.


Solution

  • The lessc command behaves the same on Windows, Mac and *n?x (albeit with a different path separator/delimiter on Windows). Google Linux/Unix discussions regarding lessc or peek at the source code to get the best understanding of it.

    If you set your input to -, then the source is read from the standard input stream (stdin) rather than a file. This is by default the keyboard, however you can use redirection/pipes to read from elsewhere.

    For example:

    curl "url of less file on the web" | lessc - | gzip -c > compressed.css.gz
    

    would read a less file from the web, compile it with lessc, compress it with gzip then write the output to a file.

    lessc - <input >output
    

    Would read the input file, compile it and write to output, identical to lessc input output

    --include-path is a bit buggy and should generally be avoided unless you absolutely need it. In theory it should work a bit like your PATH environment variable, i.e. when lessc searches for an include and can't find it in the source folder, then it searches the folders in the include path list until it finds the target.

    --compress removes whitespace, as the documentation says. --yui-compress performs other optimisations to further reduce file size, although in extremely rare cases it can create problems.