2017 © Pedro Peláez
 

yii2-extension yii2-auto-asset-bundle

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

image

yidas/yii2-auto-asset-bundle

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

  • Saturday, March 31, 2018
  • by yidas
  • Repository
  • 2 Watchers
  • 2 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 60 % Grown

The README.md

   , (*1)

Yii 2 Auto Asset Bundle


Base Asset Bundle for Yii2 to auto-allocate JS & CSS files for each View, (*2)

Latest Stable Version Latest Unstable Version License, (*3)

FEATURES

  • Each View would has it own JS & CSS asset files, (*4)

  • Standard Asset files' structure same as View paths, (*5)

  • Single AssetBundle automatically handles all Views' assets by registering, (*6)

Felt dirty of writting Javascript code in View file? Got tired of creating asset for every View files?, (*7)

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., (*8)


DEMONSTRATION

A View file which locates:, (*9)

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

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

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., (*11)


REQUIREMENTS

This library requires the following:, (*12)

  • PHP 5.4.0+
  • Yii 2.0.0+

INSTALLATION

Install via Composer in your Yii2 project:, (*13)

composer require yidas/yii2-auto-asset-bundle

CONFIGURATION

You could create an asset to extend \yidas\web\AutoAssetBundle with your application configuration:, (*14)

namespace app\assets;

class AutoAssetBundle extends \yidas\web\AutoAssetBundle {}

Customized Setting

You could customize asset to fit your application:, (*15)

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 in the content View, for example yii2-app-basic/views/controller/action.php:, (*16)

<?php

\app\assets\AutoAssetBundle::register($this);

After that, this view would auto load following files:, (*17)

yii2-app-basic/web/dist/app/controller/action.js
yii2-app-basic/web/dist/app/controller/action.css

The prefix path relates to the view path., (*18)

The Versions

31/03 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

framework yii2 asset view asset-bundle

31/03 2018

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

 

framework yii2 asset view asset-bundle

28/03 2018

0.1.0

0.1.0.0

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

  Sources   Download

MIT

The Requires

 

framework yii2 asset view asset-bundle