如何在不同的较少文件中使用变量? [英] How to use variables in different less files?

查看:64
本文介绍了如何在不同的较少文件中使用变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我将一个较少的文件分成许多较少的文件,以便于组织. 这是我的资料库:

Let's say I separate a less files into many less files to be easy to organize. Here is my repository:

/reset.less
/variables.less
/mixins.less
/main.less
/styles.less 

styles.less只是导入其他文件:

The styles.less is just importing the other files:

@import "reset.less";
@import "mixins.less";
@import "variables.less";
@import "main.less";

但是,当我在main.less中添加一些代码并使用@ line-color时,它们是在variables.less中定义的.它显示名称Error: variable @line-color is undefined,但我无法编译它-我使用PHPStorm,插件较少.

However, when I add some codes into main.less and use the @line-color which is defined in the variables.less. It shows Name Error: variable @line-color is undefined and I cannot compile it- I use PHPStorm with less plugin.

你能建议我吗?

推荐答案

您必须将variables.less导入到所有使用变量的文件中.

You have to import your variables.less to all files which use your variables.

您只需要编译style.less.您不能编译main.less,因为它不知道变量.less,但您仍然不需要main.CSS,对吗?
您应该获得正确的style.css,这是(我想)您唯一需要的css文件.

You have to compile only your style.less. You cannot compile the main.less because it doesn't know the variables.less but you don't want a main.CSS anyway, do you?
You should get the correct style.css which is (I guess) the only css file you'll need.

这篇关于如何在不同的较少文件中使用变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆