LESS variable file not global

2019-07-31 13:34发布

I use less-loader with webpack, the annoying part is I have to import the variable.less in every single of my module's less file. Why it can't be just global?

1条回答
女痞
2楼-- · 2019-07-31 13:46

It's not clear from your question (can't tell if the problem you're having is something about your webpack setup), but if you're saying you have to do

variables.less

@var1: value1;
@var2: value2;

module1.less

@import 'variables';
selectorA {
    propertyX: @var1
}

module2.less

@import 'variables';
selectorB {
    propertyY: @var2
}

you can approach it like this:

all.less (other common names for this are main.less and app.less)

@import 'variables';
@import 'module1';
@import 'module2';

variables.less

@var1: value1;
@var2: value2;

module1.less

selectorA {
    propertyX: @var1
}

module2.less

selectorB {
    propertyY: @var2
}
查看更多
登录 后发表回答