8

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?

madth3
  • 7,275
  • 12
  • 50
  • 74
  • Can you post the error printed by the LESS compiler? If you're using the PHP one it'll be an exception, or it'll most likely be in the console if you're using the JS one. – Bojangles Jan 25 '12 at 16:51
  • I'm using .net dotless extension within Visual Studio 2010. I'll update the post asap. Thanks –  Jan 25 '12 at 19:43
  • The dotLess compiler is executed within VisualStudio2010. I can't get an error message, the error code is -532459699. –  Feb 15 '12 at 08:35
  • For me it doesn't give any error when including "@import '../custom.less';" in the top of the less file. It just won't compile to a CSS file. I've tried both quotes and slash and backslash to no avail. (I'm using winless). – Polymorphix Feb 17 '12 at 11:20

4 Answers4

9

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

@import "./../style.less";  /* Correct */
@import "../style.less";    /* Wrong */
Mohebifar
  • 3,341
  • 1
  • 24
  • 32
1

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?

Community
  • 1
  • 1
Polymorphix
  • 1,066
  • 1
  • 12
  • 29
0

Try this:

@import "~/root_css_folder/parentfolder/file1.less";
Anthony
  • 12,177
  • 9
  • 69
  • 105
Brent Anderson
  • 966
  • 4
  • 6
  • This is not working. I updated the folder structure, the lambda is the root of the site. –  Jan 14 '12 at 20:39
0

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.

bzx
  • 1,364
  • 11
  • 10