JorgeGRC
JorgeGRC

Reputation: 1062

How to compile LESS into CSS when files are saved in Eclipse

I'm developing a struts2 webapp for months now using maven to manage my dependencies and I've just discovered LESS. I have installed and configured the LESS plug-in for Eclipse but it's really annoying to right click > run as > LESS compiler every time I save the .less file due to a modification of its content or something...
The thing is that I've been researching on how to plug in grunt.js (recently discovered task runners too) into maven (as explained here) but I think it's quite hard and I wondered if somebody knew an alternative to this.

In my struts2 project I have both the front and back-end of my webapp.I know it's not the right approach and if I could start all over again I would separate them into two different projects, but now it's too late (disadvantages of the learning proccess, we're not born knowing it all).

Having said all this, how can I set up a kind of task for watching my .less files and automatically compile them into .css when saved/changed?

I also found this ant task here, but I dont really know if it's what I'm looking for.

Upvotes: 0

Views: 4291

Answers (2)

agabrys
agabrys

Reputation: 9116

There are a lot of Java Less compiler (see Java Compiler for Less CSS?), so you can execute one of them by your build tool (e.g. Ant - maybe you need to write a simple Java application, which use the chosen compiler).

If you use Maven (or can switch to it) to project management, then you can use one of lesscss-maven-plugin:

Upvotes: 3

JorgeGRC
JorgeGRC

Reputation: 1062

It is possible to create an ant task to compile certain .less files into CSS whenever they are modified, and more or less is what I was looking for, but grunt seems to be more flexible as you can tell it to watch all your files with .less extension and in this solution I've found you have to declare in an .xml file the .less files you want ant to watch.

This is not explicitly what I was looking for so I'll leave this question open for now as I'll keep researching on how to make this solution more dynamic and see if it is possible to avoid the fact of defining every .less source and .css target you want.

Link to solution here

Upvotes: 0

Related Questions