LESS variable file not global

六眼飞鱼酱① 提交于 2019-12-11 06:32:14

问题


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
}


来源:https://stackoverflow.com/questions/42617057/less-variable-file-not-global

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