2013-03-13 58 views
9

我想在編譯前重載一些引導LESS變量,例如:@import後覆蓋Bootstrap LESS變量

// Core variables 
@import "variables.less"; 

// Trying to override @white from variables.less 
@white: #de1de1; 

// other bootstrap @imports.... 

上面的代碼不會覆蓋@white,但如果我在variables.less文件的末尾添加@white,它工作正常。

看來變量只能被覆蓋在同一個文件中。但是這對我來說沒有意義,因爲我認爲LESS沒有那樣工作。例如,其他@import文件(從上面的代碼中省略)使用@white變量。如果他們能夠在variables.less文件之外使用它,爲什麼我不能在文件外部覆蓋它?

我使用Less Php 0.3.9來編譯我的代碼。

注: 我只是嘗試了下面的代碼:

// Core variables 
@import "variables.less"; 
@import "variables-custom.less"; 

現在的@white值從變量 - custom.less(這在一定程度解決了我的問題)採取。它仍然不能解釋爲什麼我的原始代碼不起作用。將欣賞答案。

+2

對此有一個很好的答案http://stackoverflow.com/questions/15426256/override-less-variables – ScottS 2013-03-15 13:19:19

回答

3

變量將按照導入設置爲編譯的順序被覆蓋(並且可用)。

例如:

@import "variables.less"; //@white is set 
@import "styles.less";  //UPDATED @white NOT available 
@import "variables-custom.less"; //Update @white 
@import "styles2.less";  //UPDATED @white available 

因此,只要確保,如果你不打算使用variables.less而是一個變量 - custom.less,你把之前所有其他的.LESS文件(當然除了variables.less)。