https://github.com/yidas/yii2-auto-asset-bundle
Base Asset Bundle for Yii2 to auto-allocate JS & CSS files for each View
https://github.com/yidas/yii2-auto-asset-bundle
yii2 yii2-asset yii2-extension
Last synced: 2 months ago
JSON representation
Base Asset Bundle for Yii2 to auto-allocate JS & CSS files for each View
- Host: GitHub
- URL: https://github.com/yidas/yii2-auto-asset-bundle
- Owner: yidas
- License: mit
- Created: 2018-03-28T08:12:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-31T09:26:46.000Z (about 7 years ago)
- Last Synced: 2025-01-20T12:05:59.753Z (4 months ago)
- Topics: yii2, yii2-asset, yii2-extension
- Language: PHP
- Homepage:
- Size: 2.93 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Yii 2 Auto Asset Bundle
Base Asset Bundle for Yii2 to auto-allocate JS & CSS files for each View
[](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)
[](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)
[](https://packagist.org/packages/yidas/yii2-auto-asset-bundle)FEATURES
--------- *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.
---
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
------------This library requires the following:
- PHP 5.4.0+
- Yii 2.0.0+---
INSTALLATION
------------Install via Composer in your Yii2 project:
```
composer require yidas/yii2-auto-asset-bundle
```---
CONFIGURATION
-------------You could create an asset to extend `\yidas\web\AutoAssetBundle` with your application configuration:
```php
namespace app\assets;class AutoAssetBundle extends \yidas\web\AutoAssetBundle {}
```### Customized Setting
You could customize asset to fit your application:
```php
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
-----Register [configured asset](#configuration) in the content View, for example `yii2-app-basic/views/controller/action.php`:
```php