Code Monkey home page Code Monkey logo

yii2-auto-asset-bundle's Introduction

   

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

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:

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

USAGE

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

<?php

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

After that, this view would auto load following files:

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.

yii2-auto-asset-bundle's People

Contributors

yidas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.