In LESS CSS can I get LESS to watch a bunch of files but compile a different file when they change?

不羁岁月 提交于 2019-11-27 18:22:38

问题


I have several LESS files that are all imported into one master file (styles.less). My problem at the moment is: when I make a change in one of the child files I have to save style.less to compile it to CSS.

Is there a way in which I can ask less to monitor the child files but only compile the parent?

Cheers, Ad


回答1:


I found a solution for MY problem but it would be great for most.

As I am on a Mac I istalled less.app ( http://incident57.com/less/ ), it uses less.js to compile the less for you. As of a couple of days ago they added a new feature:

NEW FEATURE: "backwards @import parsing." If you have a file, X, that imports another file, Y, and you make changes to Y, X will now automatically recompile when you save Y (if auto-compile is on). This feature is automatic; there's nothing to turn on or hook up. You'll see "triggered by: X" in the compiler result when it happens.

Turns out it works very well indeed. Hope this helps someone!




回答2:


I've hacked a bash script called lesswatch (it doesn't support "backwards @import parsing") that uses watchdog to listen for file change events and lessc to compile to CSS. I wrote a short blog post about this today.




回答3:


There's a fork of less.js that watches file changes and even all files included via @import (like the accepted answer above):

https://github.com/wvl/less.js

The author of less.js does not want the --watch option of the old ruby version, so this fork may be your best option for now. Through node.js it can run on all platforms.




回答4:


You can use this nodejs script and do the same thing.

node less-watch-compiler.js FOLDER_TO_WATCH FOLDER_TO_OUTPUT

https://github.com/jonycheung/Dead-Simple-LESS-Watch-Compiler

It skips watching files with names that starts with underscore or a period.




回答5:


If you use Mac, I currently use less.app from Code Kit http://incident57.com/less/

It works really well.



来源:https://stackoverflow.com/questions/3854071/in-less-css-can-i-get-less-to-watch-a-bunch-of-files-but-compile-a-different-fil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!