Panos Karampis Panos Karampis - 3 months ago 29
Less Question

lesscss @import with absolute path

I am having issue trying to refer from a less file another less file using absolute syntax:

Less file A with location

$find `pwd` -name auth0.less
/Users/panos/dcimsupport/struxureon/auth0/src/main/resources/css/auth0.less


imports Less file B

@import '/bootstrap/less/so_colors.less';


Now, the so_colors.less has location

find `pwd` -name so_colors.less
/Users/panos/dcimsupport/struxureon/auth0/src/main/resources/bootstrap/less/so_colors.less


The above fails with

java.io.FileNotFoundException: File /Users/panos/dcimsupport/struxureon/auth0/src/main/resources/css/bootstrap/less/so_colors.less


It seems that lesscss is like jailed to the css folder. I know that if I import as ../bootstrap/.....less it will work but then I have to go as up in directories as required which i'd rather not. Is there some other solution to that? There is limitation though, that bootstrap folder cannot be under css folder

I have used both

<groupId>biz.gabrys.maven.plugins</groupId>
<artifactId>lesscss-maven-plugin</artifactId>


and

<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>


with configuration such as

<configuration>
<sourceDirectory>${project.basedir}/src/main/resources</sourceDirectory>
<outputDirectory>${project.basedir}/target/classes/resources</outputDirectory>
<compress>true</compress>
<includes>
<include>css/**/*.less</include>
<include>layouts/**/*.less</include>
<include>page/**/*.less</include>
<include>pages/**/*.less</include>
</includes>



Answer

How plugins works

The biz.gabrys.maven.plugins plugin treats the path /bootstrap/less/so_colors.less as an absolute. It does not set the sourceDirectory as a root, so it is looking for /bootstrap/less/so_colors.less instead of /Users/panos/dcimsupport/struxureon/auth0/src/main/resources/bootstrap/less/so_colors.less. That file does not exist so the plugin uses fallback and treats it as a relative to /Users/panos/dcimsupport/struxureon/auth0/src/main/resources/css/auth0.less. That is the reason why it is looking for /Users/panos/dcimsupport/struxureon/auth0/src/main/resources/css/bootstrap/less/so_colors.less.

The org.lesscss plugin works similar.


Your idea for improvement

I can try to add such improvement to my plugin, but first I need finish some migration process. Unfortunately this means that I can release that improvement not in the near future (e.g. at the end of 2016).

The org.lesscss plugin is not supported by the author and no one else.


Solution

For now you can only use relative paths with ../.