vnxdev / yii2-assets-optimizer

Yii2 扩展,用于自动压缩和合并 CSS 和 JS 文件。旨在易于使用,开箱即用。

此包的官方仓库似乎已不存在,因此该包已被冻结。

安装: 317

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 1

开放问题: 0

类型:yii2-extension

1.0.0 2018-03-13 20:21 UTC

This package is not auto-updated.

Last update: 2021-07-10 12:11:03 UTC


README

自动压缩和合并 CSS 和 JS 文件,无需配置。

Yii2 扩展,用于自动压缩和合并 CSS 和 JS 文件。旨在易于使用,开箱即用。

安装

安装此扩展的首选方式是通过 composer

运行以下命令:

php composer.phar require --prefer-dist vnxdev/yii2-assets-optimizer "^1.0"

或添加以下内容:

"vnxdev/yii2-assets-optimizer": "^1.0"

如何使用

  • assetsOptimizer 条目添加到 bootstrap 部分
  • assetsOptimizer 配置数组添加到 components 部分
[
    'bootstrap'    => ['assetsOptimizer'],
    'components'    =>
    [
    //....
        'assetsOptimizer' =>
        [
            'class' => 'vnxdev\Yii2AssetsOptimizer\AssetsOptimizer',
            'enabled' => true
        ],
    //....
    ]
]

配置选项

    'assetsOptimizer' =>
    [
        'class' => 'vnxdev\Yii2AssetsOptimizer\AssetsOptimizer',
        
        // Enable or disable the component
        'enabled' => true,
        
        // Time in seconds for reading each external asset file
        'readFileTimeout' => 2,
        
        // Combine all CSS files into a single file
        'cssFilesCombine' => true, 
        
        // Download all external CSS files
        'cssFilesRemoteEnable' => true,
        
        // Enable compression for CSS files
        'cssFilesCompress' => true,
        
        // Move down CSS files to the bottom of the page
        'cssFilesToBottom' => true,
        
        // Combine all JS files into a single file
        'jsFilesCombine' => true,
        
        // Download all external JS files
        'jsFilesRemoteEnable' => true,
        
        // Enable compression for JS files
        'jsFilesCompress' => true,
        
        // Remove all JS files inside AJAX responses
        'clearJsOnAjax' => true,
        
        // Remove all JS files inside PJAX responses
        'clearJsOnPjax' => true,
        
        // Skip already minified files
        'skipMinified' => true,
        
        // Pattern to detect minified files
        'skipMinifiedPattern' => '.min',
        
        // Whitelist app routes
        // If not empty, only these app routes will use this extension
        // If entry is present in whitelist and blacklist at the same time, blacklist has higher priority
        // Example config: extension will work only with SiteController and actionIndex.
        // Leave this option empty for extension to work everywhere
        'routesWhitelist' => [
            'site' => [
                'index'
            ]
        ],
        
        // Blacklist app routes
        // If not empty, these app routes will be excluded from using this extension
        // Example config: extension will NOT work with SiteController and actionIndex
        // Leave this option empty for extension to work everywhere        
        'routesBlacklist' => [
            'site' => [
                'index'
            ]
        ],
    ],