导入带有变量的 LESS CSS 文件
我有 2 个名为 core.less 和 style.less 的 LESS CSS 文件
core.less 位于: \css\core.less ,其内容如下:
body {
background: @bg_color;
color: @font_color;
}
style.less 位于: \css\green\style.less 及其内容如下:
@bg_color: #0F0;
@font_color: #FFF;
@import "../../core.less";
core.less 文件包含所有 CSS 规则,采用 LESS 格式,但不提供变量的定义。
style.less定义了core.less中引用的所有变量,然后导入core.less文件。
我编译 style.less 没有问题,因为它从核心文件导入所有规则。 core.less 文件无法编译 - 它将生成错误,因为它不包含变量定义。
我现在也想编译 core.css 文件(只是为了确保我的 LESS 规则中没有错误)。有没有什么方法可以在 core.less 文件中添加某种虚拟/占位符变量,这样它也可以在不生成错误的情况下进行编译,并且仍然可以使用我上面解释的设置?
我愿意接受有关更改文件格式/结构的建议。
I have 2 LESS CSS files called core.less and style.less
core.less is located under: \css\core.less and its contents are below:
body {
background: @bg_color;
color: @font_color;
}
style.less is located under: \css\green\style.less and its contents are below:
@bg_color: #0F0;
@font_color: #FFF;
@import "../../core.less";
The core.less file contains all the css rules, in LESS format, but does not provide the definitions for the variables.
The style.less defines all the variables referenced in core.less, and then imports the core.less file.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将core.less导入style.less,您编译了core.less的“LESS规则”。
By importing core.less into style.less you are compiling the "LESS rules" of core.less.
也许您不应该在
core.less
之外定义core.less
中所需的变量。我通常使“核心”文件(实际上是任何编程语言)不依赖于其余代码。Perhaps you should not define variables, needed in
core.less
, outside ofcore.less
. I typically make "core" files (in any programming language, really) have no dependencies on the rest of the code.