what a part does bower/bower-asset play in php application such as yii2

為{幸葍}努か 提交于 2020-01-04 01:50:47

问题


Recently I deployed some projects like trntv/yii2-starter-kit and so on.but all applications are publishing assets on '@vendor/bower' instead of'@vendor/bower/bower-asset'. I have read the question Yii2 Composer manage package in bower and bower-vendor and solved it . but I still feel confused about the directory vendor/bower/bower-asset.
What's the part does bower/bower-asset play in php application? it is not a composer package but many theme store in there. Furthermore, bower is a dependency management for javascript just like Composer for PHP , but how does it solve dependency for js package by PHP on this occasion that I have not install node.js environment?


回答1:


The idea of Composer Asset Plugin is to download Bower / NPM packages and manage their dependencies without having Node JS, Bower and NPM installed (through PHP / Composer). Also it adds possibility to add JavaScript dependencies for PHP packages that use JavaScript libraries.

See for example yii2-bootstrap Yii2 extension (PHP) has a dependency on Bootstrap (JS + CSS):

"bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*"

When you run composer install or composer update, all JS dependencies will be installed to vendor/bower folder.

This is built into the core, but very ambiguous, receives a lot of criticism and there are plans to remove it in 2.1.0 (as far as I remember, it was included before release of 2.0 even it was unstable). Unfortunately this is required and there is no normal way to disable it.

You can read more info on the extension's Github page.

As for folder name, it should be named bower, not bower-asset, if you installed everything correctly.

It's named like so automatically, make sure you have the latest version of plugin:

composer global require "fxp/composer-asset-plugin:~1.1.1"

I'd recommend to even switch to:

composer global require "fxp/composer-asset-plugin:*"

If you have problems or errors, execute:

composer global remove "fxp/composer-asset-plugin"

Then reinstall it again, delete vendor and composer.lock in your application folder and run:

composer install


来源:https://stackoverflow.com/questions/34939713/what-a-part-does-bower-bower-asset-play-in-php-application-such-as-yii2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!