jarrus90 / yii2-asset-converter
此包已被废弃,不再维护。未建议替代包。
Sass, Scss 转换器 for Yii2。无需系统要求。支持 yii2-composer,可自定义输出目录
1.0.7
2015-11-09 10:45 UTC
Requires
- php: >=5.4.0
- leafo/scssphp: *
- yiisoft/yii2: 2.*
- yiisoft/yii2-composer: 2.*
This package is not auto-updated.
Last update: 2020-01-24 16:01:36 UTC
README
仅适用于 YII2 的新资产管理器,无需外部工具和可执行文件即可将 Less 和 Sass 文件转换为 CSS。使用 PHP 库将 Sass 和 Less 文件转换为 CSS。它替换了使用外部工具的 AssetConverter。Less 和 Sass 文件根据时间源文件依赖关系进行转换。
注意:模块处于初始开发阶段。任何内容都可能在任何时候更改。
为此项目做出贡献
任何人都可以为此项目做出贡献。请花点时间查看贡献指南。
许可
Yii2-asset-converter 在 BSD-3-Clause 许可下发布。有关详细信息,请参阅打包的 LICENSE.md。
##要求
YII 2.0
##使用方法
- 使用 Composer 安装
"require": { "jarrus90/yii2-asset-converter": "1.*", }, php composer.phar update
- 修改配置文件 {app}/protected/config/main.php 中的 assetManager
'assetManager' => array( 'bundles' => require(__DIR__ . '/assets.php'), 'converter'=>array( 'class'=>'jarrus90\assetConverter\Converter', ) ),
- 在
- 享受吧!
- 扩展名为 .sass 的文件将转换为 .css 文件
- 扩展名为 .less 的文件将转换为 .css 文件
- 扩展名为 .scss 的文件将转换为 .css 文件
##资产配置文件示例 /protected/config/assets.php
return array( 'app' => array( 'basePath' => '@webroot', 'baseUrl' => '@web', 'css' => array( 'css/bootstrap.min.css', 'css/bootstrap-responsive.min.css', 'css/site.css', 'css/less_style.less', 'css/sass_style.sass', ), 'js' => array( ), 'depends' => array( 'yii', ), ), );
##编译文件在哪里?
默认情况下,它位于 @webroot/compiled,但您可以通过配置中的 destinationDir 属性进行更改
完整配置
'components' => array( 'assetManager' => array( 'converter'=>array( 'class'=>'jarrus90\assetConverter\Converter', 'force'=>false, // true : If you want convert your sass each time without time dependency 'destinationDir' => 'compiled', //at which folder of @webroot put compiled files 'parsers' => array( 'sass' => array( // file extension to parse 'class' => 'jarrus90\assetConverter\Sass', 'output' => 'css', // parsed output file type 'options' => array( 'cachePath' => '@app/runtime/cache/sass-parser' // optional options ), ), 'scss' => array( // file extension to parse 'class' => 'jarrus90\assetConverter\Sass', 'output' => 'css', // parsed output file type 'options' => array() // optional options ), ) ) ), ),
此外,对于 SCSS 文件,您还可以使用备用配置
'components' => array( 'assetManager' => array( 'converter'=>array( // ... 'parsers' => array( // ... 'scss' => array( // file extension to parse 'class' => 'jarrus90\assetConverter\Scss', 'output' => 'css', // parsed output file type 'options' => array( // optional options 'enableCompass' => true, // default is true 'importPaths' => array(), // import paths, you may use path alias here, // e.g., `['@path/to/dir', '@path/to/dir1', ...]` 'lineComments' => false, // if true — compiler will place line numbers in your compiled output 'outputStyle' => 'nested', // May be `compressed`, `crunched`, `expanded` or `nested`, // see more at https://sass-lang.cn/documentation/file.SASS_REFERENCE.html#output_style ), ), ), ), ), // ...