Base Asset Bundle for Yii2 to auto-allocate JS & CSS files for each View

1.0.0 2018-03-31 09:26 UTC

This package is auto-updated.

Last update: 2024-07-10 20:11:53 UTC



Yii 2 Auto Asset Bundle

Base Asset Bundle for Yii2 to auto-allocate JS & CSS files for each View

Latest Stable Version Latest Unstable Version License


  • Each View would has it own JS & CSS asset files

  • Standard Asset files' structure same as View paths

  • Single AssetBundle automatically handles all Views' assets by registering

Felt dirty of writting Javascript code in View file? Got tired of creating asset for every View files?

If each View need Javascript & CSS for it self, the AssetBundle library allocates pairs of asset files for each registered View, which each View's path is same as allocated assets path with base path setting.


A View file which locates:


After registering AutoAssetBundle, the View file would auto-load above assets files if exist:


dist/app/ is the prefix base path which could be customized.


This library requires the following:

  • PHP 5.4.0+
  • Yii 2.0.0+


Install via Composer in your Yii2 project:

composer require yidas/yii2-auto-asset-bundle


You could create an asset to extend \yidas\web\AutoAssetBundle with your application configuration:

namespace app\assets;

class AutoAssetBundle extends \yidas\web\AutoAssetBundle {}

Customized Setting

You could customize asset to fit your application:

namespace app\assets;

class AutoAssetBundle extends \yidas\web\AutoAssetBundle
    // Base path & url for each view's asset in your application
    public $basePath = '@webroot/dist/app';
    public $baseUrl = '@web/dist/app';
    public $depends = [


Register configured asset in the content View, for example yii2-app-basic/views/controller/action.php:



After that, this view would auto load following files:


The prefix path relates to the view path.