1 回答

TA貢獻1860條經驗 獲得超9個贊
根據我在他們的文檔中的理解: https ://scssphp.github.io/scssphp/docs/
當您使用 @import 指令導入文件時,您的 PHP 腳本的當前路徑默認用作搜索路徑。這通常不是您想要的,因此有兩種操作導入路徑的方法:addImportPath 和 setImportPaths。
addImportPath($path) 將 $path 附加到搜索的導入路徑列表中。
setImportPaths($pathArray) 將用 $pathArray 替換整個導入路徑。如果 $pathArray 的值不是一個數組,它將被轉換為一個數組。
所以,我會這樣做:
$scss = new \Leafo\ScssPhp\Compiler();
$scss_path = base_path('public/assets/tmpl-scss/style.scss');
$scss->setImportPaths([
'public/assets/tmpl-scss/'
'public/assets/tmpl-scss/base/',
'public/assets/tmpl-scss/abstracts/',
'public/assets/tmpl-scss/layout/',
'public/assets/tmpl-scss/components/',
]);
$scss->setVariables($colors);
$css = $scss->compile('@import "'.$scss_path.'"');
在 CSS 中:
.my-parent-container {
background-color: $body-background;
}
@import 'reset';
@import 'placeholders';
@import 'typography';
@import 'header';
@import 'buttons';
@import 'switch_button';
此外,您可能想看看源地圖:https ://scssphp.github.io/scssphp/docs/#source-maps
我不確定這是否可行,因為我從未親自使用過 Leafo ScssPhp。但是你可以試試這個,它可能會給你一個起點。
- 1 回答
- 0 關注
- 164 瀏覽
添加回答
舉報