lsat/yii2-bower-asset

Bower Assets for Yii 2 app provided via Composer repository

Installs: 2 189

Dependents: 1

Suggesters: 0

Security: 0

Type:yii2-extension

v2.1.2 2024-06-22 05:42 UTC

This package is auto-updated.

Last update: 2024-10-29 05:47:33 UTC


README

   

Yii 2 Core Bower Asset


Yii 2 official Composer repository solution for Bower Assets

Latest Stable Version Latest Unstable Version License

FEATURES

1. Install or update Bower assets for Yii 2 app via Composer without any plugin (Even v2.0.13 above)

2. Prevent the error of Bower packages when using Composer install & update for Yii2

Problem 1

- yiisoft/yii2 2.0.12 requires bower-asset/jquery 2.2.@stable | 2.1.@stable | 1.11.@stable | 1.12.@stable -> no matching package found.

3. Official install way by using original Composer repository

Got tired of fxp/composer-asset-plugin? It's a good project with nice idea and good implementation. But it has some issues: it slows down composer update a lot and requires global installation, so affects all projects. Also there are Travis and Scrutinizer integration special problems, that are a bit annoying.

Compare with Asset Packagist, this package goals to install the Bower assets for Yii2 app by original Composer repository, and makes Bower and Composer separated.

Supported Packages

This Bower asset supports Yii 2 core(yiisoft/yii2) such as widgets or validators.

For the Yii 2 application templates(yii2-app-basic & yii2-app-advanced), this also supports yii2-bootstrap and others for dependent packages such as yii2-debug & yii2-gii.

INSTALLATION

1. Require Package

In Yii2 composer.json, require lsat/yii2-bower-asset before yiisoft/yii2.

Example composer.json:

"require": {
    "php": ">=5.4.0",
    "lsat/yii2-bower-asset": "~2.1.1",
    "yiisoft/yii2": "~2.0.50",
    "yiisoft/yii2-bootstrap": "~2.0.0"
    "mdmsoft/yii2-admin": "~3.0"
}

After v2.1.1 Support "mdmsoft/yii2-admin": "~3.0"

After above setting, it's same as lsat/yii2-composer-bower-skip which makes composer to install and update for Yii2 without Bower plugin.

2. Set Up Application Config

In Yii2 application config/web.php, added an alias named @bower pointed to @vendor/lsat/yii2-bower-asset/bower:

$config = [
    ...
    'aliases' => [
        '@bower' => '@vendor/lsat/yii2-bower-asset/bower'
    ],
    ...
];

This method is the better way with efficient and clean considering. Instead, you could also use installer to set up:

Install via Package Cloning Installer

Install via Alias Setting Installer

3. Remove Composer Asset-Packagist Repositories

If you are using the version 2.0.13 or higher of Yii, you may remove the repositories setting of composer.json to use original Composer repository.

Example segament to delete in composer.json :

"repositories": [
    {
        "type": "composer",
        "url": "https://asset-packagist.org"
    }
]

Finally, command composer update then enjoy it.

CREATE PROJECT

If you doesn't has Yii2 project yet, choose one of below ways to create:

Create Project via Composer

You can use Composer to create Yii2 project by using following package:

lsat/yii2-app-basic

composer create-project --prefer-dist lsat/yii2-app-basic

lsat/yii2-app-advanced

composer create-project --prefer-dist lsat/yii2-app-advanced

These packages are Yii 2 Application Template with fixed Bower, which including lsat/yii2-bower-asset already.

Creating Project from Official Site

You could download Yii2 project from official Archive File, then manally install yii2-bower-asset on it by following above instruction.

INSTALLER USAGE

If you don't want to Set Up Application Config but use installer instead, there are some ways you could chooses one of them to install:

Install via Package Cloning Installer

In Yii2 composer.json, add script lsat\\yii2BowerAsset\\Installer::bower in post-package-install & post-package-update event.

"scripts": {
    "post-package-install": [
         "lsat\\yii2BowerAsset\\Installer::clone"
    ],
    "post-package-update": [
         "lsat\\yii2BowerAsset\\Installer::clone"
    ]
}

Install via Alias Setting Installer

In Yii2 composer.json, add script lsat\\yii2BowerAsset\\Installer::setAlias in post-update-cmd event.

"scripts": {
    "post-package-install": [
         "lsat\\yii2BowerAsset\\Installer::setAlias"
    ],
    "post-package-update": [
         "lsat\\yii2BowerAsset\\Installer::setAlias"
    ],
    "unset-yii2-bower-asset": [
        "lsat\\yii2BowerAsset\\Installer::unsetAlias"
    ]
}

This installation will modify Yii2 file, you can run composer run-script unset-yii2-bower-asset to recover back.

LIMITATION

Do not use Bower mixed with Composer project is the goal of this package.

  1. The variety of Bower packages are just for Yii2 cores.

  2. The versions of Bower packages are fixed to current Yii2 version.

  3. If you are requiring other Bower packages in Yii2, you could set the config fit to this package or not to use.