Importing LESS CSS Files with variables

此生再无相见时 提交于 2019-12-11 10:04:01

问题


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.


回答1:


By importing core.less into style.less you are compiling the "LESS rules" of core.less.




回答2:


Perhaps you should not define variables, needed in core.less, outside of core.less. I typically make "core" files (in any programming language, really) have no dependencies on the rest of the code.



来源:https://stackoverflow.com/questions/5532754/importing-less-css-files-with-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!