2013-07-11 75 views
20

在更短的,我可以做這樣的事情變量可以用於Sass文件的導入語句嗎?

@basePath:"../../some_crazy_project_path_to_repeat/less/"; 
@import "@{basePath}less.less"; 

所以我試圖做同樣的事情在薩斯

$basePath:"../../some_crazy_project_path_to_repeat/less/"; 
@import "${basePath}less.scss"; 
// Syntax error: File to import not found or unreadable: ${basePath}less.scss. 

@import "#{basePath}less.scss"; 
// Syntax error: File to import not found or unreadable: #{basePath}less.scss. 

有沒有辦法在這樣做薩斯?

+6

[字符串插值](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#interpolation_)使用'#{}' – steveax

+0

@steveax插值是一個非常酷的功能,但我可以'在我的頭上圍繞它如何幫助這種情況? – Shanimal

+0

您是否試過'@import「#{basePath} less.scss」'? –

回答

9

您不能在SASS中使用條件填充進口。

考慮在項目中創建一個Compass擴展。

+4

Andrey是正確的,來自[Sass'@ import'文檔](http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#import):「導入可能包含#{}插值,但僅限於有一定的限制,不能根據變量動態導入Sass文件;插值僅適用於CSS導入,因此只能在url()導入時使用。 – steveax

6

如前所述,您不能在導入路徑中使用變量。你可以做的是使用-I--load-path選項來指定要從中搜索的目錄。

sass --watch sass/:css/ --load-path ../../path/to/library/ 

比方說,你有這樣的目錄結構:

themes 
    hotdog 
     _variables.scss 
    classic 
     _variables.scss 
styles.scss 

你styles.scss應該有相對於所提供的負載路徑(S)輸入路徑:

// note the import here doesn't contain themes, hotdog, or classic 
@import "variables"; 

@debug $foo; 

你的命令看起來像這樣:

# hotdog 
sass styles.scss hotdog.css --load-path ./themes/hotdog/ 
# classic 
sass styles.scss classic.css --load-path ./themes/classic/ 

有關更多信息,請參閱Sass options documentation

相關問題