lucidtaz / yii2-scssphp
scssphp的Yii2绑定
0.3.1
2024-08-29 07:17 UTC
Requires
- php: >=7.1.0
- scssphp/scssphp: ^1.0
- yiisoft/yii2: ^2.0.13
Requires (Dev)
- guzzlehttp/guzzle: ^6.3
- phpstan/phpstan: ^0.11.2
- phpstan/phpstan-phpunit: ^0.11.0
- phpunit/phpunit: ^7.5
README
Yii2绑定的SCSS-PHP
此库提供将scssPhp/scssphp轻松集成到Yii2中的方法。Scssphp是一个本地的PHP SCSS(SASS)编译器。这使您在使用Yii的资产发布方式时可以无缝使用SCSS。
用法
配置web.php
以禁用Yii的内置资产转换器并使用新的转换器
<?php $config = [ // Other configuration... 'components' => [ 'assetManager' => [ 'converter' => 'lucidtaz\yii2scssphp\ScssAssetConverter', ], // Other components... ], // Other configuration... ];
如果AppAsset
位于/assets
目录中,而scss文件位于/assets/source/site.scss
,则您的AppAsset.php
可能如下所示
<?php namespace app\assets; use yii\web\AssetBundle; class AppAsset extends AssetBundle { public $sourcePath = '@app/assets/source'; public $css = [ 'site.scss', ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; }
换句话说,您只需在$css
数组中使用.scss
文件即可。
自定义SCSS解析器
如果需要更多灵活性,可以自定义底层的yii2-scssphp库。为此,可以在DI容器中覆盖ScssPhp\ScssPhp\Compiler
对象的属性,如下所示
<?php $config = [ // Other configuration... 'components' => [ 'assetManager' => [ 'converter' => 'lucidtaz\yii2scssphp\ScssAssetConverter', ], // Other components... ], 'container' => [ 'definitions' => [ \ScssPhp\ScssPhp\Compiler::class => function () { // You can also use a child class here: $compiler = new \ScssPhp\ScssPhp\Compiler(); $compiler->setOutputStyle(\ScssPhp\ScssPhp\OutputStyle::COMPRESSED); return $compiler; } ], ], // Other configuration... ];
从Yii 2.0.11开始支持在config.php
中的这种用法。在此之前,您应该直接使用DI容器。在这种情况下,请参阅Yii依赖注入的readme。
贡献
在贡献代码时,请确保测试通过。此外,代码将通过phpstan检查以检测任何静态分析可识别的问题。
要运行这些检查,只需执行composer ci
。
尽管如此,当测试失败时,请不要犹豫贡献代码。如果您需要在您的pull request中使构建绿色,只需在PR中告诉我。