Importing LESS CSS Files with variables

2019-08-12 09:32发布

问题:

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.



标签: css less