简体   繁体   English

使用Codekit解决LESS中@import行为的困惑

[英]Confusion surrounding @import behaviour in LESS, using Codekit

Currently using Bootstrap, compiling with Codekit, and also have a separate style.less that I'm working on. 目前正在使用Bootstrap,使用Codekit进行编译,并且还有一个单独的style.less,我正在努力。

In variables.less: 在variables.less:

@blue: #0096EF;

In style.less, I have the following: 在style.less,我有以下内容:

.title-text {color: @blue;}
@import: "variables.less";

In bootstrap.less: 在bootstrap.less:

@import: "style.less";
@import: "variables.less";

Am I doing this right? 我这样做了吗? To my mind, when bootstrap is compiled it results in variables.less occurring twice. 在我看来,当编译bootstrap时,它会导致变量无效。

you should be able to go with import of variables.less once in bootstrap as first import instance, and do not include it second time in actual style.less. 你应该能够在bootstrap中作为第一个导入实例导入变量。并且不要在实际样式中第二次包含它。 Because you are right on your assumption, it will import variable.less again. 因为你的假设是正确的,它将再次导入variable.less。 meaning you are importing same variables in two locations. 意味着您在两个位置导入相同的变量。

PS as long as variables.less that defines variables that you will be using is imported before you access variables themselves you will be fine. PS只要variable.less定义你将使用的变量是在你自己访问变量之前导入的,你会没事的。

@color-black: #000;

.color {
      color: @color-black;
}

I discovered this is also a Codekit issue too, as I am using Codekit to compile the less files. 我发现这也是一个Codekit问题,因为我使用Codekit编译较少的文件。

Solution: 解:

  1. Create style.less and edit it as intended, reference @blue variable (not declared in current document) 创建style.less并按预期编辑它,引用@blue变量(未在当前文档中声明)
  2. On save, Codekit returns a compile error, due to un-declared variable in style.less. 在保存时,由于style.less中未声明的变量,Codekit返回编译错误。 Ignore the error. 忽略错误。
  3. In bootstrap.less @import style.less 在bootstrap.less @import style.less
  4. Save bootstrap.less, it compiles without issue 保存bootstrap.less,它编译没有问题
  5. Call bootstrap.css in the html doc 在html doc中调用bootstrap.css

Incidentally, I encountered a Codekit bug between step 2 and 3. After step 2, Codekit no longer watches or compiles anything. 顺便说一句,我在第2步和第3步之间遇到了Codekit错误。在第2步之后,Codekit不再监视或编译任何内容。 To solve, I needed to remove the watched project and then re-add it to Codekit. 要解决这个问题,我需要删除已监视的项目,然后将其重新添加到Codekit中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM