yanli0303/yii-minify-client-script-package 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yanli0303/yii-minify-client-script-package

最新稳定版本:v0.4

Composer 安装命令:

composer require yanli0303/yii-minify-client-script-package

包简介

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

README 文档

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

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固