微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用scssphp更改scss变量

我正在使用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更改为blue,然后进行编译,并且我确定上面显示的方式不正确.

但是,有一种方法可以将$color的变量更改为blue,而不是重新编译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();
} 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐