DotLess - 如何在父文件夹中导入 LESS 文件?

发布于 2024-12-27 05:25:40 字数 296 浏览 3 评论 0原文

我有这样的文件夹结构:

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

我想要做的是将 file1.less 导入到 file2.less 中,因此在我的 file2.less 中我有以下代码:

@import "../file1.less";

这不起作用,并且在构建项目时编译器崩溃。 我在 Visual Studio 2010 中执行编译器。

如何导入放置在父文件夹中的 less 文件?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

伤痕我心 2025-01-03 05:25:40

您必须将 ./ 添加到您的路径中。例如 :

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

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

@import "./../style.less";  /* Correct */
@import "../style.less";    /* Wrong */
咆哮 2025-01-03 05:25:40

这似乎是 LESS 中的一个错误。

bug 报告中的评论表明它已在主分支中修复,因此如果您从 git 获取最新版本,也许它会起作用。

请参阅https://github.com/cloudhead/less.js/issues/177 以及 StackOverflow 上的这篇文章:Node.js + Express.js。如何渲染更少的CSS?

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?

挖个坑埋了你 2025-01-03 05:25:40

我刚刚测试了导入一个文件,该文件比您的方式高一级,并且它对我有用。编译器崩溃时的错误是什么?该错误可能会对您有所帮助。

顺便说一句,您可能应该以不同的方式保持 .less 文件的结构。

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.

赠佳期 2025-01-03 05:25:40

试试这个:

@import "~/root_css_folder/parentfolder/file1.less";

Try this:

@import "~/root_css_folder/parentfolder/file1.less";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文