yanli0303/yii-minify-client-script-package

This package is abandoned and no longer maintained. No replacement package was suggested.

A PHP console application for minifying JavaScript and CSS files of a PHP Yii web application.

v0.4 2015-06-10 03:04 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:48:47 UTC


README

By Yan Li

Build Status Coverage Status License PayPayl donate button

A PHP console application for minifying JavaScript and CSS files of a PHP Yii web application.

Usage

  1. Minify JavaScript and CSS files with Ant-MinifyJsCss

    ant -Dsrc="path to Yii web application webroot" minify

  2. Download yiimin.phar from downloads

  3. 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:

  1. Open a new terminal window, change current directory to YiiWebApp
  2. 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

  1. Install composer and run composer install
  2. Install PHPUnit and run phpunit

Build PHAR from source

  1. Download box.phar
  2. Open a new terminal/command prompt window, change current directory to this console application
  3. Run php /path/to/box.phar build, new yiimin.phar will be created in downloads