PHP code example of lajax / yii2-asset-minifier

1. Go to this page and download the library: Download lajax/yii2-asset-minifier 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/ */

    

lajax / yii2-asset-minifier example snippets


'bootstrap' => ['assetMinifier'],
'components' => [
    // ...
    'assetMinifier' => [
        'class' => \lajax\assetminifier\Component::className(),
    ],
    // ...
],
// ...

'bootstrap' => ['assetMinifier'],
'components' => [
    // ...
    'assetMinifier' => [
        'class' => \lajax\assetminifier\Component::className(),
        'minifyJs' => true,                     // minify js files. [default]
        'minifyCss' => true,                    // minify css files [default]
        'combine' => true,                      // combine asset files. [default]
        'createGz' => false,                    // create compressed .gz file, (so the web server doesn’t need to
                                                // compress asset files on each page view). Requires
                                                // special web server configuration. [default]
        'minifier' => [                         // Settings of the components performing the minification of asset files
            'workPath' => lajax\assetminifier\Minifier::WORKPATH_SOURCE, // default setting
            'js' => '', // override default minifier, see available minifiers below
            'css' => '', // override default minifier, see available minifiers below
        ],
        'combiner' => [
            'class' => 'lajax\assetminifier\Combiner',
            'combinedFilesPath' => '/lajax-asset-minifier'      // default setting
        ]
    ],
    // ...
]
// ...

'js' => [                           // minify js via web API
    'class' => 'lajax\assetminifier\minifiers\WebJsMinifier',
    'url' => 'http://javascript-inifier.com/raw'   // default setting
],
'css' => [
    'class' => 'lajax\assetminifier\minifiers\WebCssMinifier',
    'url' => 'http://cssminifier.com/raw'           // default setting
]

'js' => [                                        // Default JS minifier.
    'class' => 'lajax\assetminifier\minifiers\PhpJsMinifier',
    // default settings, you can override them
    'options' => [
       'flaggedComments' => true                // Disable YUI style comment preservation.
    ]
],
'css' => [                                       // Default CSS minifier.
    'class' => 'lajax\assetminifier\minifiers\PhpCssMinifier',
    // default settings, you can override them
    'filters' => [
        'ImportImports' => false,
        'RemoveComments' => true,
        'RemoveEmptyRulesets' => true,
        'RemoveEmptyAtBlocks' => true,
        'ConvertLevel3AtKeyframes' => false,
        'ConvertLevel3Properties' => false,
        'Variables' => true,
        'RemoveLastDelarationSemiColon' => true
    ],
    'plugins' => [
        'Variables' => true,
        'ConvertFontWeight' => true,
        'ConvertHslColors' => true,
        'ConvertRgbColors' => true,
        'ConvertNamedColors' => true,
        'CompressColorValues' => true,
        'CompressExpressionValues' => true,
    ]
]

'js' => [
    'class' => 'lajax\assetminifier\minifiers\CliJsMinifier',
    // default settings, you can override them
    'command' => 'java -jar ' . Yii::getAlias('@vendor/packagist/closurecompiler-bin/bin/compiler.jar') . ' --js {from}',
],
'css' => [
    'class' => 'lajax\assetminifier\minifiers\CliCssMinifier',
    // default settings, you can override them
    'command' => 'java -jar ' . Yii::getAlias('@vendor/packagist/yuicompressor-bin/bin/yuicompressor.jar') . ' --type css {from}',
]

php composer.phar