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

4

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?

Ashly answered 13/1, 2012 at 11:55 Comment(4)
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.Newmarket
I'm using .net dotless extension within Visual Studio 2010. I'll update the post asap. ThanksAshly
The dotLess compiler is executed within VisualStudio2010. I can't get an error message, the error code is -532459699.Ashly
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).Indoor
I
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?

Indoor answered 17/2, 2012 at 11:28 Comment(0)
K
9

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

@import "./../style.less";  /* Correct */
@import "../style.less";    /* Wrong */
Koehler answered 19/3, 2014 at 11:59 Comment(1)
I updated lessc to version 2.1.1 and @import "../style.less"; works as expected.Awfully
I
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?

Indoor answered 17/2, 2012 at 11:28 Comment(0)
A
0

Try this:

@import "~/root_css_folder/parentfolder/file1.less";
Alight answered 13/1, 2012 at 17:45 Comment(1)
This is not working. I updated the folder structure, the lambda is the root of the site.Ashly
R
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.

Remmer answered 17/1, 2012 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.