As discussed in less/less.js#192
Call this with a command like:
$ lessc -w -x base.less base.css
8 Feb 17:26:10 - Change detected... Updated
One issue is that a parse error will cause the system to exit and you have to relaunch it. I also don't think it will watch imported stylesheets. Perhaps is there a better way to do this?
Add 'watch' option to command line lessc
Looks good -- you also want to process the file when you first launch. I made that change here:
Also, I pushed a bunch of changes that avoid the process.exit, so you do not have to relaunch the script on errors. I'll add a separate pull request for that change.
Any idea when this will be merged in? Maybe we can get a 1.1.4 release with this functionality?
I've made a lesswatch command that can be used to watch entire directories, rather than just watching one file. It just automatically compiles .less files into their .css counterparts, so you don't have to specify output files.
Try it out and let me know what you think
When developing, you can use watch-mode in the browser, by adding #!watch to the url, I don't want this as part of the command line tool.
This is essential to the command-line tool, why wouldn't you want it? It's the most reliable way to use LESS in a development environment and have an exported CSS always ready for deploy.
I don't serve out the .less files directly to the browser so intentionally nerfing this feature of the command line tool seems a bit strange to me. I can understand wanting to keep a single way of doing things because it would be simpler but I don't think there would be a lot of confusion around this.
Cloudhead, could you elaborate on why you don't want this in the command line tool? It seems like the perfect place for this kind of functionality.
I'd also like to know why? I use kicker to get around this on OS X but it makes working on Linux or Windows a pain in the ass.
The watch command is also very important to me. This makes the use cases of lessc a lot more broader.
Everbody who migrates from sass or the less.js ruby version can keep their workflow.
There is a discussion on why here: #246 (comment)
As I mentioned in issue #192 — those still looking for a solution to this, I recommend Coyote http://github.com/imulus/coyote
Coyote is a tool allowing you to watch source files for Coffescript, SASS, or LESS and then compile them on the fly. Example: coyote -w input.less:output.css
Please add this life saver to command line!
@umrashrf As the other discussion says, there are already plenty of tools that do watching for multiple pre-compiled languages like LESS, CoffeeScript, Jade, etc. Look into Grunt or Gulp if you'd like to watch and build from the command line.
If anyone wants a new repo on less that is a watcher and then wants to help us refactor lessc to integrate with that watcher then they are more than welcome, but given grunt and gulp its not on my list of priorities.
Not only Grunt and Gulp, but the multitude of other GUI-based compilers with watchers as well. I think it's a duplication of effort and something others have done a better job solving already. Not to mention avoiding all the inevitable watcher-related issues that will clutter the issue tracker.