PHP Composer - set provider directory

I am having trouble setting up a provider path for a Yii2 application. I am adding a couple of lines to the composer.json file, which I get from the main Yii2 application template. All I want to do is change the location of my supplier assets.

Below are the changes I made to the files, but I get this error:

The file or directory to be published does not exist: /path/to/app/vendor/bower/jquery/dist 

But I expect this particular asset to be published:

 /path/to/vendors/bower/jquery/dist 

No matter what I do, I still get this error message. I suspect this is a Yii2 problem, not a composer problem, but I'm not sure. Does anyone have any idea? Thanks in advance.

Files ...

index.php

 // comment out the following two lines when deployed to production defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require('/path/to/vendors/autoload.php'); require('/path/to/vendors/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php'); (new yii\web\Application($config))->run(); 

composer.json

 { "name": "yiisoft/yii2-app-basic", "description": "Yii 2 Basic Project Template", "keywords": ["yii2", "framework", "basic", "project template"], "homepage": "http://www.yiiframework.com/", "type": "project", "license": "BSD-3-Clause", "support": { ... }, "minimum-stability": "dev", "config": { "process-timeout": 1800, "vendor-dir": "/path/to/vendors" }, "require": { "fxp/composer-asset-plugin": "~1.0", ... }, "extra": { "asset-installer-paths": { "npm-asset-library": "../../includes/vendors/npm", "bower-asset-library": "../../includes/vendors/bower" } } } 
+7
php bower yii2 composer-php
source share
3 answers

It turns out there is a simple solution: if you want to change the location of your supplierโ€™s assets, you have to follow these simple steps:

  • include composer asset plugin in composer.json file

     "require": { "fxp/composer-asset-plugin": "*" } 
  • include the linker-asset-plugin directive in your additional configuration. in composer.json file:

     "extra": { "asset-installer-paths": { "npm-asset-library": "../../path/to/vendors/npm", "bower-asset-library": "../../path/to/vendors/bower" } } 
  • add the provider location to the configuration section in the composer.json file:

     "config": { "vendor-dir": "../../path/to/vendors" } 
  • update web / index.php to point to the new provider location:

     require(__DIR__ . '/../../../path/to/vendors/autoload.php'); require(__DIR__ . '/../../../path/to/vendors/yiisoft/yii2/Yii.php'); 
  • include the vendorPath definition in your config / web.php:

     'vendorPath' => '../../../path/to/vendors', 

This should work with the basic vanilla Yii2 pattern.

+10
source share

This works for me:

 sudo cp -R bower-asset/* bower 

Just copy all the files and folders from bower-asset to bower.

+2
source share
+1
source share

All Articles