專欄內容備份:https://www.bestyii.com/topic/1
在yii中引用php的開源項目用composer已經很方便了,引用前端的開源項目也有composer的插件fxp-asset和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',
],
...
];