lesscss-engine
lesscss-engine copied to clipboard
@import resources from the classpath
I cannot @import a file from a different folder (but on the classpath).
How does the LessEngine load files for @import?
Example:
@import "test.less"
where test.less isn't in the same folder but its parent is added to the java classpath?
Have you tried @import "../test.less"? For classpath imports we use @import "classpath:META-INF/less/import.less".
Yes, using the notation @import "classpath:..."; does work
But I cannot use that notation because I'm trying to use the same .less file in production (compiled with asual engine) and in development (using the traditional less.js browser mode).
Is there any way the asual engine to do this automatically behind the scenes? First try to import relative to working directory, then check the classpath if unable to find the file.
It will be great if you can do this with relative paths. I will check if a classpath fallback is possible.
Thanks.
Something as simple as wrapping the call in a try-catch block and then checking the classpath (both with the "classpath:" notation and without) should work.
This can be implemented using the changes introduced with https://github.com/asual/lesscss-engine/pull/32
You need to override the default resource loading configuration by adding a variant of ClasspathResourceLoader
that will check if the resource is present on the classpath even if no 'classpath:' prefix was given in the @include directive:
import com.asual.lesscss.loader.ClasspathResourceLoader;
class ClasspathFallbackResourceLoader
extends ClasspathResourceLoader {
ClasspathFallbackResourceLoader(ClassLoader cl) {
super(cl);
}
@Override
protected String getSchema() {
return "";
}
}
then you can combine it with regular ClasspathResourceLoader
using ChainedResourceLoader
and pass it to LessEngine.init
.