0
我有一個common.scss
跨多個項目共享。這個文件有幾行應該爲新項目刪除。是否可以使用將從common.scss
減去CSS選項創建文件?使用SCSS從另一個文件中抽取一個文件
我有一個common.scss
跨多個項目共享。這個文件有幾行應該爲新項目刪除。是否可以使用將從common.scss
減去CSS選項創建文件?使用SCSS從另一個文件中抽取一個文件
您可以創建一個布爾變量並將代碼行包裝在if語句中。例如:
// common.scss
$include_extra_css: true;
// global css here
@if $include_extra_css {
// special css here
}
然後,相應地爲每個項目更改$ include_extra_css的值。
但是:如果common.scss是您導入到另一個主Sass文件的部分(_common.scss)會更好。這樣,您可以對變量使用!default標誌,然後在任何文件導入時更改其值,而不必在每個項目的common.scss中修改其值。 (請注意,將直接編譯的Sass文件導入另一個直接編譯的Sass文件是一種不好的做法)。像這樣:
// common.scss
$include_extra_css: true !default;
// global css here
@if $include_extra_css {
// special css here
}
// otherfile.scss
$include_extra_css: false;
@import "_common.scss";
這裏有默認的薩斯文檔:http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#variable_defaults_