DotLess - How to import a LESS file in a parent folder?

6.4k views Asked by At

I have this folders structure:

~/css/file1.less
~/css/folder/file2.less

What I want to do is importing file1.less inside file2.less, so in my file2.less I have this code:

@import "../file1.less";

This do not work, and the compiler crash when I build the project. I execute the compiler in Visual Studio 2010.

How can I import a less file placed in a parent folder?

4

There are 4 answers

0
Polymorphix On BEST ANSWER

This seems to be a bug in LESS.

Comments in the bug report suggests that it is fixed in the main branch, so if you get the latest version from git, maybe it will work.

See https://github.com/cloudhead/less.js/issues/177 and this post on StackOverflow: Node.js + Express.js. How to RENDER less css?

0
bzx On

I just tested importing a file which is one level up the way you did it and it works for me.. What's the compiler's error on crash? The error may help you.

On a sidenote, you should probably keep your .less files structured differently.

1
Brent Anderson On

Try this:

@import "~/root_css_folder/parentfolder/file1.less";
1
Mohebifar On

You must prepend ./ to your path. For example :

@import "./../style.less";  /* Correct */
@import "../style.less";    /* Wrong */