本文介绍了LESS变量文件不是全局的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在webpack中使用了less-loader,烦人的部分是我必须在模块的less文件的每个文件中导入variable.less.为什么它不能只是全球性的?

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?

推荐答案

问题尚不清楚(无法确定您遇到的问题是否与Webpack设置有关),但是如果您说的是必须要做的

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
}

您可以这样处理:

all.less (其他通用名称是main.lessapp.less)

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
}

这篇关于LESS变量文件不是全局的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:06