导入带有变量的LESS CSS文件 [英] Importing LESS CSS Files with variables
问题描述
我有2个LESS CSS文件,分别称为core.less和style.less
I have 2 LESS CSS files called core.less and style.less
core.less位于:\ css \ core.less下,其内容如下:
core.less is located under: \css\core.less and its contents are below:
body {
background: @bg_color;
color: @font_color;
}
style.less位于:\ css \ green \ style.less下,其内容如下:
style.less is located under: \css\green\style.less and its contents are below:
@bg_color: #0F0;
@font_color: #FFF;
@import "../../core.less";
core.less 文件包含LESS格式的所有css规则,但未提供变量的定义.
The core.less file contains all the css rules, in LESS format, but does not provide the definitions for the variables.
style.less 定义core.less中引用的所有变量,然后导入core.less文件.
The style.less defines all the variables referenced in core.less, and then imports the core.less file.
我编译style.less没问题,因为它从核心文件中导入了所有规则. core.less文件无法编译-由于它不包含变量定义,因此会生成错误.
I have no problems compiling style.less as it imports all the rules from the core file. The core.less file cannot be compiled - it will generate errors since it does not contain the variable definitions.
我现在也想编译 core.css 文件(只是为了确保我的LESS规则中没有错误).是否有任何方法可以在core.less文件中添加某种虚拟/占位符变量,以便也可以在不产生错误的情况下对其进行编译,并且仍然可以使用我上面已经解释过的设置?
I would now like to compile the core.css file as well (just to make sure there are no errors in my LESS rules). Is there any way of adding some kind of dummy/placeholder variables in the core.less file such that it can also be complied without generating errors and still work with the setup I have explained above?
我愿意接受有关更改文件格式/结构的建议.
I am open to suggestions on changing the format / structure of the files.
推荐答案
通过将 core.less 导入到 style.less 中,您正在进行编译core.less的少规则".
By importing core.less into style.less you are compiling the "LESS rules" of core.less.
这篇关于导入带有变量的LESS CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!