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:
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
}