PHPackages                             yidas/yii2-auto-asset-bundle - 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. [Framework](/categories/framework)
4. /
5. yidas/yii2-auto-asset-bundle

ActiveYii2-extension[Framework](/categories/framework)

yidas/yii2-auto-asset-bundle
============================

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

1.0.0(8y ago)3781MITPHP

Since Mar 31Pushed 8y ago3 watchersCompare

[ Source](https://github.com/yidas/yii2-auto-asset-bundle)[ Packagist](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)[ RSS](/packages/yidas-yii2-auto-asset-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii 2 Auto Asset Bundle
=======================

[](#yii-2-auto-asset-bundle)

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

[![Latest Stable Version](https://camo.githubusercontent.com/c3b581e96db772820231f527b6cfb38c5b5f094d9b7e46f8d63bdec11bea11c9/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f796969322d6175746f2d61737365742d62756e646c652f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/b349121224609560f175c89d8ee82f0301bb82b2fb8e2324be04cd031fada0b3/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f796969322d6175746f2d61737365742d62756e646c652f762f756e737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)[![License](https://camo.githubusercontent.com/13e9cec4d028b53af4a2a21fd670613e192fe7ee67441effcc8250eced9a1c3d/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f796969322d6175746f2d61737365742d62756e646c652f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)

FEATURES
--------

[](#features)

- *Each View would has it own **JS &amp; 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* &amp; *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.

---

DEMONSTRATION
-------------

[](#demonstration)

A View file which locates:

```
yii2-app-basic/views/site/about.js

```

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

```
yii2-app-basic/web/dist/app/site/about.js
yii2-app-basic/web/dist/app/site/about.css

```

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

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP 5.4.0+
- Yii 2.0.0+

---

INSTALLATION
------------

[](#installation)

Install via Composer in your Yii2 project:

```
composer require yidas/yii2-auto-asset-bundle

```

---

CONFIGURATION
-------------

[](#configuration)

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

[](#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 = [
        'app\assets\AppAsset',
    ];
}
```

---

USAGE
-----

[](#usage)

Register [configured asset](#configuration) in the content View, for example `yii2-app-basic/views/controller/action.php`:

```
