在yii中引用php的开源项目用composer已经很方便了,引用前端的开源项目也有composer的插件fxp-asset和Asset Packagistphp
之前yii默认采用前者,如今新的yii2模版默认采用后者,后者的做者就很厉害了,貌似是个重度yii用户,看来是被fxp-asset的执行缓慢给弄急眼了,因此本身搞了个更新的方法。
言归正传:
因此更快速的安装方式就是 Asset Packagist https://asset-packagist.org前端
其实就是2步:git
"config": { "process-timeout": 1800, "fxp-asset": { "enabled": false } }, "repositories": [ { "type": "composer", "url": "https://asset-packagist.org" } ]
若是composer的源采用阿里云镜像,完整写法以下:github
"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路径: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路径yii2
$config = [ ... 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], ... ];