PHP code example of tquant / yii2-asset-combiner

1. Go to this page and download the library: Download tquant/yii2-asset-combiner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tquant / yii2-asset-combiner example snippets



$config = [
    //...
    'controllerMap' => [
        'asset-combiner' => [
            'class' => 'AssetCombiner\AssetCombinerController',
            'aliases' => [
                '@webroot' => '@app/web',
                '@web' => '/',
            ],
            'assetManager' => [
                'basePath' => '@webroot/assets',
                'baseUrl' => '@web/assets',
            ],

            // Output puth and url
            //'outputPath' => '@webroot/assets/ac',
            //'outputUrl' => '@web/assets/ac',

            // directory where all assets stored
            //'assetsDir' => '@app/assets',

            // assets namespace
            //'assetsNamespace' => 'app\assets',
            
            // recursive search for assets
            //'recursive' => true,
            
            // process dependent assets
            //'processDependent' => true,

            // Additional bundles to minify
            //'bundles' => [
            //    'yii\web\YiiAsset',
            //    'yii\web\JqueryAsset',
            //],
            
            // Function to calc the file hash, by default is "filemtime"
            //'fileHashFunction' => function ($path) {return hash_file('crc32', $path);},

            // Filter to process JS files. If not set, then SimpleJsFilter will be used
            'filterJs' => [
                'class' => 'AssetCombiner\filters\UglifyJsFilter',
                'sourceMap' => false,
                'compress' => false,
                'mangle' => false,
            ],

            // Filter to process JS files. If not set, then SimpleCssFilter will be used
            'filterCss' => 'AssetCombiner\filters\UglifyCssFilter',
        ],
    ],
];

$config = [
    ...
    'components' => [
        ...
        'view' => [
            'class' => 'yii\web\View',
            'as assetCombiner' => [
                'class' => 'AssetCombiner\AssetCombinerBehavior',

                // Output puth and url
                //'outputPath' => '@webroot/assets/ac',
                //'outputUrl' => '@web/assets/ac',

                // Filter to process JS files. If not set, then SimpleJsFilter will be used
                'filterJs' => [
                    'class' => 'AssetCombiner\filters\UglifyJsFilter',
                    'sourceMap' => false,
                    'compress' => false,
                    'mangle' => false,
                ],

                // Filter to process JS files. If not set, then SimpleCssFilter will be used
                'filterCss' => 'AssetCombiner\filters\UglifyCssFilter',
            ],
        ],
    ],
],

class AppAsset extends AssetBundle {
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        ...,
    ];
    public $js = [
        ...,
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
        'yii\bootstrap\BootstrapPluginAsset',
    ];

    // Mark asset as monolith
    public $publishOptions = [
        'monolith' => true,
    ];
}


$config = [
    // ...
    'controllerMap' => [
        'asset-combiner' => [
            'class' => 'AssetCombiner\AssetCombinerController',
            'assetManager' => [
                'basePath' => '@webroot/assets',
                'baseUrl' => '@web/assets',
            ],
            'filterJs' => [
                'class' => 'AssetCombiner\filters\UglifyJsFilter',
                'sourceMap' => false,
                'compress' => true,
                'mangle' => true,
            ],
            'filterCss' => 'AssetCombiner\filters\UglifyCssFilter',
            // Function to calc the file hash, by default is "filemtime"
            //'fileHashFunction' => function ($path) {return hash_file('crc32', $path);},
        ],
    ],
];


$config = [
    //...
    'components' => [
        //...
        'view' => [
            'class' => 'yii\web\View',
            'as assetCombiner' => [
                'class' => 'AssetCombiner\AssetCombinerBehavior',
            ],
        ],
        'assetManager' => [
            'bundles' => 
bash
./yii asset-combiner config/assets.php