[英]leafo/scssphp Ignoring files in sub-directories
leafo/scssphp works fine, except when the files are in the sub-directories, I tried addImportPath but still couldn't include those sub-directory files, here is my scss code. Leafo/scssphp 工作正常,除非文件在子目录中,我尝试了 addImportPath 但仍然无法包含那些子目录文件,这是我的 scss 代码。
.my-parent-container {
background-color: $body-background;
@import './base/reset';
@import './abstracts/placeholders';
@import './base/typography';
@import './layout/header';
@import './components/buttons';
@import './components/switch_button';
}
PHP code PHP代码
$scss = new \Leafo\ScssPhp\Compiler();
$scss_path = base_path('public/assets/tmpl-scss/style.scss');
$scss->setVariables($colors);
$css = $scss->compile('@import "'.$scss_path.'"');
the files such as reset, placeholders, typography,header,buttons and switch_button are not added.未添加重置、占位符、排版、标题、按钮和开关按钮等文件。
Thank you谢谢
From what I can understand in their documentation: https://scssphp.github.io/scssphp/docs/从我在他们的文档中可以理解的内容: https : //scssphp.github.io/scssphp/docs/
When you import a file using the @import directive, the current path of your PHP script is used as the search path by default.
当您使用 @import 指令导入文件时,默认情况下您的 PHP 脚本的当前路径将用作搜索路径。 This is often not what you want, so there are two methods for manipulating the import path: addImportPath, and setImportPaths.
这通常不是您想要的,因此有两种方法可以操作导入路径:addImportPath 和 setImportPaths。
addImportPath($path) will append $path to the list of the import paths that are searched.
addImportPath($path) 将 $path 附加到搜索的导入路径列表中。
setImportPaths($pathArray) will replace the entire import path with $pathArray.
setImportPaths($pathArray) 将用 $pathArray 替换整个导入路径。 The value of $pathArray will be converted to an array if it isn't one already.
如果 $pathArray 的值不是一个数组,它将被转换为一个数组。
So, I would do it like this:所以,我会这样做:
$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.'"');
And in the CSS:在 CSS 中:
.my-parent-container {
background-color: $body-background;
}
@import 'reset';
@import 'placeholders';
@import 'typography';
@import 'header';
@import 'buttons';
@import 'switch_button';
Also, you might want to take a look at source maps: https://scssphp.github.io/scssphp/docs/#source-maps另外,您可能想看看源地图: https : //scssphp.github.io/scssphp/docs/#source-maps
I am not sure if this will work because I never personally used the Leafo ScssPhp.我不确定这是否可行,因为我从未亲自使用过 Leafo ScssPhp。 But you can try this and it might give you a starting point.
但是你可以试试这个,它可能会给你一个起点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.