【问题标题】:Use variables in LESS import statements在 LESS 导入语句中使用变量
【发布时间】:2015-03-27 01:36:36
【问题描述】:

如果我要从同一个目录导入多个文件,我想重用目录路径(假设带有 import 语句的文件与导入目标不在同一目录中)。到目前为止,我已经尝试过:

@directoryPath: "../modules/core/less/";

@import @directoryPath + "file.less";
@import (@directoryPath + "file.less");
@import @{directoryPath}"file.less";
@import "@{directoryPath}file.less";

@filePath: @directoryPath + "file.less"; //I have verified this produces the proper string

@import @filePath;
@import @{filePath};

这 6 个 import 语句都不起作用。他们中的一些人在

source: url(/*LESS variables*/);

声明,但在@import 语句中的工作方式不同。有什么想法可行吗?

【问题讨论】:

  • 是否可以让 grunt 在运行 lessc 命令之前插入文件名?
  • 这个@import "@{directoryPath}file.less";其实是对的。但看起来您正在使用lessphp(因为在标准中,@directoryPath + "file.less"; 是无效语句)并且它根本不支持导入的字符串插值。
  • 我相信你列出的两个陈述都有错误,但我会再次检查。
  • 您的第一条语句奏效了。如果你把它变成一个答案,我会把它标记为正确的。

标签: css less


【解决方案1】:

参见the documentation 中的Variables > Variable Interpolation > Import statements

正确的语法是:

@path: "../modules/core/less/";

@import "@{path}file.less";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 2013-07-10
    相关资源
    最近更新 更多