Yii2 Composer manage package in bower and bower-vendor

后端 未结 3 1564
感情败类
感情败类 2021-01-26 07:44

I have been using yii2 for sometime now but i cant wrap my head around how to manage my packages. I have two issues in these regard.

  1. when i add a package to yii

相关标签:
3条回答
  • 2021-01-26 08:30

    I faced this issue a little while ago, and it drove me crazy!

    The solution is actually quite simple (isn't it always?) - you need to delete the fxp directory in your Composer common directory and clear the composer cache - composer global clearcache - and remove the fxp plugin line from your global composer.json and re-require it.

    No matter what I did, the bower packages was installed in vendor/bower/bower-asset or other weird places.

    The solution that helped me was to get rid of the fxp plugin and re-require it. Try that.

    The Composer asset plugin is buggy, but useful.

    Hope this helps ! :)

    Edit: The problem that you are facing is simply that the Composer assets plugin refuses to parse the asset installation paths that is clearly defined in your composer.json file. After having tested the behaviour in my own project, I created a 'vanilla' basic application and even an advanced application: same behaviour. So, I re-required/re-installed the asset plugin and that fixed it.

    0 讨论(0)
  • 2021-01-26 08:32

    This can be archived by overwriting the default alias path for bower packages which is @vendor/bower to @vendor/bower/bower-asset.

    This can be done from the web.php file under $config=[]

     'aliases' => [
            '@bower' => '@vendor/bower/bower-asset',
        ],
    

    when you echo

    echo Yii::getAlias('@bower');
    

    it should echo

    /Library/WebServer/Documents/project-name/vendor/bower/bower-asset
    
    0 讨论(0)
  • 2021-01-26 08:34

    This is how we register booty assets.

    namespace backend\assets;
    
    
    use yii\web\AssetBundle;
    
    class BootstrapAsset extends AssetBundle
    {
        public $sourcePath = '@bower/bootstrap/dist';
        public $js         = [
            'js/bootstrap.min.js',
        ];
    }
    

    And Register this asset in your layout as:

    $asset     = AppAsset::register($this);
    $bootstrap = \backend\assets\BootstrapAsset::register($this);
    

    Hope this will give a hint.

    0 讨论(0)
提交回复
热议问题