Yii2 composer安裝慢的解決辦法

下面由composer使用教程欄目給大家介紹yii2 composer安裝慢的解決辦法。

Yii2 composer安裝慢的解決辦法

在yii中引用php的開源項目用composer已經很方便了,引用前端的開源項目也有composer的插件fxp-asset(https://github.com/fxpio/composer-asset-plugin)和Asset Packagist(https://github.com/hiqdev/asset-packagist)

以前yii默認采用前者,現在新的yii2模版默認采用后者,后者的作者就很厲害了,貌似是個重度yii用戶,看來是被fxp-asset的執行緩慢給弄急眼了,所以自己搞了個更新的方法。

言歸正傳:

所以更快速的安裝方式就是 Asset Packagist https://asset-packagist.org

其實就是2步:

在config中關閉fxp-asset的調用

在源列表中加入asset-packagist庫的配置

"config":?{ ????????"process-timeout":?1800, ????????"fxp-asset":?{ ????????????"enabled":?false? ????????} ????}, ???? ?"repositories":?[ ????{ ????????"type":?"composer", ????????"url":?"https://asset-packagist.org" ????} ]

如果composer的源采用阿里云鏡像,完整寫法如下:

"repositories":?{ ????????"0":?{ ????????????"type":?"composer", ????????????"url":?"https://asset-packagist.org" ????????}, ????????"packagist":?{ ????????????"type":?"composer", ????????????"url":?"https://mirrors.aliyun.com/composer/" ????????} ????}

需要注意的是,yii在yiibaseApplication 中定義vendor路徑的時候也定義了bower和npm路徑:

????/** ?????*?Sets?the?directory?that?stores?vendor?files. ?????*?@param?string?$path?the?directory?that?stores?vendor?files. ?????*/ ????public?function?setVendorPath($path) ????{ ????????$this->_vendorPath?=?Yii::getAlias($path); ????????Yii::setAlias('@vendor',?$this->_vendorPath); ????????Yii::setAlias('@bower',?$this->_vendorPath?.?DIRECTORY_SEPARATOR?.?'bower'); ????????Yii::setAlias('@npm',?$this->_vendorPath?.?DIRECTORY_SEPARATOR?.?'npm'); ????}

這就和asset-packagist的默認安裝路徑有了差別解決辦法:

重新定義yii中的bower和npm路徑

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

更多composer技術文章,可以訪問composer使用教程使用教程欄目!

以上就是Yii2

? 版權聲明
THE END
喜歡就支持一下吧
點贊10 分享