cornernote/yii-asset-compress
Composer 安装命令:
composer require cornernote/yii-asset-compress
包简介
Command to merge and minify assets for Yii
README 文档
README
Command to merge and minify assets for Yii.
Features
- Merges and minifies lists of CSS or JS files into a single CSS or JS files.
- Replaces releative
url()in CSS files - Publishes required assets so that relative assets are available
Installation
Please download using ONE of the following methods:
Composer Installation
All requirements are automatically downloaded into the correct location when using composer. There is no need to download additional files or set paths to third party files.
Get composer:
curl http://getcomposer.org/installer | php
Install latest release OR development version:
php composer.phar require cornernote/yii-asset-compress:* // latest release
php composer.phar require cornernote/yii-asset-compress:dev-master // development version
Add the vendor folder to the aliases in your yii configuration:
return array( 'aliases' => array( 'vendor' => '/path/to/vendor', ), );
Manual Installation
Download the latest release or development version and move the commands/AssetCompressCommand.php file into your protected/commands folder.
In addition the following are required:
Configuration
Add to your yii console config:
return array( 'commandMap' => array( 'assetCompress' => array( 'class' => 'vendor.cornernote.yii-asset-compress.commands.AssetCompressCommand', 'assetsPath' => 'application.assets', 'css' => array( 'combine' => array( 'css/combined.css' => array( // output to application.assets|css/desktop.css // format is: asset.path.alias|path/to/asset.css 'vendor.twbs.bootstrap.dist|css/bootstrap.css', // -{ (alias!=application) = this asset path will be 'bootstrap.assets|css/yiistrap.css', // -{ published, and any url() in the CSS will be 'vendor.fortawesome.font-awesome|css/font-awesome.min.css', // -{ replaced with the correct relative path. 'application.assets|css/app.css', // -{ 'application|css/app.css', // - (alias=application) = Uses webroot, assets not published. ), ), 'minify' => true ), 'js' => array( 'combine' => array( 'js/combined.js' => array( // output to application.assets|js/desktop.js // format is: asset.path.alias|path/to/asset.js 'system.web.js.source|jquery.min.js', // -{ (alias!=application) = this asset path will be 'system.web.js.source|jquery.yiiactiveform.js', // -{ published, and any url() in the CSS will be 'vendor.twbs.bootstrap.dist|js/bootstrap.js', // -{ replaced with the correct relative path. 'application.assets|js/app.js', // -{ 'application|js/app.js', // - (alias=application) = Uses webroot, assets not published. ), ), 'minify' => true ) ), ), );
Compressing Assets
Run using your yiic command:
php yiic assetCompress
Using Assets
To display your combined assets on your page you can use the following in your layout file:
$baseUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.assets')); Yii::app()->clientScript->registerCssFile($baseUrl . '/css/combined.css'); Yii::app()->clientScript->registerScriptFile($baseUrl . '/js/combined.js');
Supressing Merged Assets
Now that you have jQuery and Bootstrap (and others) merged, you don't want them to output. One method is to overwrite CClientScript:
<?php class ClientScript extends CClientScript { public $ignoreCoreScript = array(); public $ignoreScriptFile = array(); public $ignoreCssFile = array(); public function registerCoreScript($name, $options = array()) { if (in_array($name, $this->ignoreCoreScript)) return $this; return parent::registerCoreScript($name); } public function registerScriptFile($url, $position = null, array $htmlOptions = array()) { foreach ($this->ignoreScriptFile as $ignore) if ($this->endsWith($url, $ignore)) return $this; return parent::registerScriptFile($url, $position, $htmlOptions); } public function registerCssFile($url, $media = '') { foreach ($this->ignoreCssFile as $ignore) if ($this->endsWith($url, $ignore)) return $this; return parent::registerCssFile($url, $media); } private function endsWith($haystack, $needle) { $length = strlen($needle); if ($length == 0) return true; return (substr($haystack, -$length) === $needle); } }
Set this up in your config as follows:
return array( 'components' => array( 'clientScript' => array( 'class' => 'application.components.ClientScript', 'ignoreCssFile' => array( 'bootstrap.css', 'yiistrap.css', 'font-awesome.min.css', ), 'ignoreScriptFile'=>array( 'bootstrap.js', ), 'ignoreCoreScript' => array( 'jquery', 'yiiactiveform', ), ), ), );
Resources
Support
- Does this README need improvement? Go ahead and suggest a change.
- Found a bug, or need help using this project? Check the open issues or create an issue.
License
BSD-3-Clause, Copyright © 2017 Mr PHP
cornernote/yii-asset-compress 适用场景与选型建议
cornernote/yii-asset-compress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.32k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii」 「mrphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cornernote/yii-asset-compress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cornernote/yii-asset-compress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cornernote/yii-asset-compress 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Gii ModelDoc Generator for Yii framework
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
CKFinder Assets
Interactive Javascript Charts - JS Only
CKEditor Assets
Priveate for SkeekS CMS
统计信息
- 总下载量: 12.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2016-04-29
