Yii2-composer安装慢的解决办法

6次阅读

共计 975 个字符,预计需要花费 3 分钟才能阅读完成。

在 yii 中引用 php 的开源项目用 composer 已经很方便了,引用前端的开源项目也有 composer 的插件 fxp-asset 和 Asset Packagist

以前 yii 默认采用前者,现在新的 yii2 模版默认采用后者,后者的作者就很厉害了,貌似是个重度 yii 用户,看来是被 fxp-asset 的执行缓慢给弄急眼了,所以自己搞了个更新的方法。
言归正传:
所以更快速的安装方式就是 Asset Packagist https://asset-packagist.org

其实就是 2 步:

  1. 在 config 中关闭 fxp-asset 的调用
  2. 在源列表中加入 asset-packagist 库的配置
"config": {
        "process-timeout": 1800,
        "fxp-asset": {"enabled": false}
    },
    
 "repositories": [
    {
        "type": "composer",
        "url": "https://asset-packagist.org"
    }
]

需要注意的是,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',
        ],
        ...
    ];

正文完
 0