我正在使用 scssphp 来查看是否可以使用它来更改在现有 scss 中设置的变量,因此我设置了一个测试用例:
require_once "scssphp-0.1.7/scss.inc.php";
use Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Server;
$scss = new Compiler();
$scss->addImportPath('testsass');
$scss->compile('$color: blue;');
$test = $scss->compile('@import "test.scss"');
echo $test;
我的 test.scss 看起来像:
$color: red;
body {
background: $color;
}
现在我希望我可以在我的 php 中将 $color 更改为蓝色然后编译它,我确定上面显示的方式不正确。
但有没有办法将 $color 的变量更改为蓝色,而不是重新编译我的 test.scss?
最佳答案
我自己用一个完美无缺的解决方法来回答这个问题。 我制作了一个 config.scss,其中包含我所有的变量。并决定在编译导入 config.scss 的 layout.scss 之前打开并重写它
require_once "scssphp-0.1.7/scss.inc.php";
use Leafo\ScssPhp\Compiler;
use Leafo\ScssPhp\Server;
$scss = new Compiler();
$scss->setImportPaths('sass');
//$txt = '$color: yellow;';
$txt = '$font: "Open sans";';
$txt .= '$body-font-size: 15px;';
$txt .= '$containerWidth: 1140px;';
$txt .= '$gutter-size: 15px;';
$txt .= '$primarycolor: red;';
$txt .= '$secondarycolor: blue;';
$txt .= '$background: #e8e3e3;';
$txt .= '$textcolor: $primarycolor;';
$txt .= '$linkcolor: #000;';
$file = fopen('sass/_configuratie.scss', "w");
if (fwrite($file, $txt)) {
$server = new Server('sass', null, $scss);
$server->serve();
}
关于php - 用 scssphp 更改 scss 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31314057/