php - 用 scssphp 更改 scss 变量

标签 php sass

我正在使用 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/

相关文章:

php - 无法编译php --with-libmemcached-dir无法识别?

java - Java 中的 AES 加密与 PHP 不同

不支持 flexbox 遗留的 CSS flexbox SASS mixin

javascript - 使用 gulp-sourcemaps 的文件名不正确

php - 忽略将数据导出到 php mysql 中的 csv 文件的空列

PHP 从 2 个字符串变量生成一个 zip 文件

php - 如何将新版本的 phpmyadmin 安装到服务器上?

javascript - SASS 部分导入在 react 中不起作用

sass - 在每个文件中添加 common.sass 文件

CSS calc() 与多个单位相乘