yanli0303 / yii-minify-client-script-package
A PHP console application for minifying JavaScript and CSS files of a PHP Yii web application.
Requires
- php: >=5.3
- nikic/php-parser: ^1.3
- symfony/console: ^2.6
Requires (Dev)
- kherge/box: ^2.5
- phpunit/phpunit: ~4.5
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2020-01-24 15:48:47 UTC
README
By Yan Li
A PHP console application for minifying JavaScript and CSS files of a PHP Yii web application.
Usage
-
Minify JavaScript and CSS files with Ant-MinifyJsCss
ant -Dsrc="path to Yii web application webroot" minify
-
Download yiimin.phar from downloads
-
Open a new command/terminal window, change current directory to the Yii web app webroot, and execute following command
php yiimin.phar minify -v
Example
Take the YiiWebApp in tests as an example, suppose you have 3 client script packages defined in Yii web app config file protected/config/main.php:
'clientScript' => array( 'class' => 'CClientScript', 'packages' => array( 'jquery' => array( 'baseUrl' => '//code.jquery.com/', 'js' => array('jquery-1.11.3.min.js') ), 'layout' => array( 'baseUrl' => 'css/layout', 'css' => array('pageHeader.css', 'pageFooter.css') ), 'homePage' => array( 'baseUrl' => '', 'depends' => array('jquery', 'layout'), 'js' => array('js/homePage/homePage.js'), 'css' => array('css/homePage/homePage.css') ) ) )
Firstly you need to minify each local JavaScript and CSS files, after doing so, you'll have the following files:
- css/layout/pageHeader.min.css
- css/layout/pageFooter.min.css
- css/homePage/homePage.min.css
- js/homePage/homePage.min.js
Then, with this tool:
- Open a new terminal window, change current directory to YiiWebApp
- Run
php yiimin.phar minify -v
After that, your config file will be changed to:
'clientScript' => array( 'class' => 'CClientScript', 'packages' => array( 'jquery' => array( 'baseUrl' => '//code.jquery.com', 'js' => array('jquery-1.11.3.min.js') ), 'layout' => array( 'baseUrl' => '', 'css' => array('assets/layout_d7863...48618.min.css') ), 'homePage' => array( 'baseUrl' => '', 'depends' => array('jquery'), 'css' => array('assets/homePage_d8e21...fa8f7.min.css'), 'js' => array('assets/homePage_8cc59...57c458.min.js') ) ) )
And the assets/homePage_d8e21...fa8f7.min.css comprises the contents of following files:
- css/layout/pageHeader.min.css
- css/layout/pageFooter.min.css
- css/homePage/homePage.min.css
Limitations
- Better to only register one client script package on a page/view. If you registered several packages on a page, make sure the packages don't depend on a same package, otherwise the resources of the shared package will be loaded on the page multiple times;
- Don't use registerCssFile or registerScriptFile anymore; use registerPackage instead.
Run tests
Build PHAR from source
- Download box.phar
- Open a new terminal/command prompt window, change current directory to this console application
- Run
php /path/to/box.phar build
, new yiimin.phar will be created in downloads