在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', ], ... ];