PHPackages                             cornernote/yii-asset-compress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cornernote/yii-asset-compress

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cornernote/yii-asset-compress
=============================

Command to merge and minify assets for Yii

1.0.1(10y ago)312.3k1BSD-3-ClausePHPPHP &gt;=5.3.0

Since Apr 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/cornernote/yii-asset-compress)[ Packagist](https://packagist.org/packages/cornernote/yii-asset-compress)[ RSS](/packages/cornernote-yii-asset-compress/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Yii Asset Compress
==================

[](#yii-asset-compress)

Command to merge and minify assets for Yii.

Features
--------

[](#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
------------

[](#installation)

Please download using ONE of the following methods:

### Composer Installation

[](#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

[](#manual-installation)

Download the [latest release](https://github.com/cornernote/yii-asset-compress/releases/latest) or [development version](https://github.com/cornernote/yii-asset-compress/archive/master.zip) and move the `commands/AssetCompressCommand.php` file into your `protected/commands` folder.

In addition the following are required:

- [tedious/JShrink](https://github.com/tedious/JShrink)
- [mrclay/minify](https://github.com/mrclay/minify)

Configuration
-------------

[](#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
------------------

[](#compressing-assets)

Run using your `yiic` command:

```
php yiic assetCompress

```

[![command](https://cloud.githubusercontent.com/assets/51875/14907318/2b09d194-0e06-11e6-8f9b-2ae796191e2b.png)](https://cloud.githubusercontent.com/assets/51875/14907318/2b09d194-0e06-11e6-8f9b-2ae796191e2b.png)

Using Assets
------------

[](#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
------------------------

[](#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:

```
