小编给大家分享一下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在yii\base\Application 中定义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',
],
...
];
看完了这篇文章,相信你对“Yii2 composer安装慢怎么办”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。