Reputation: 1469
I'm having trouble configuring the vendor path for a Yii2 application. I am adding a couple of lines to the composer.json file I get from the Yii2 basic app template. All I want to do is change the location of my vendor assets.
Below are the changes I have 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'm expecting that particular asset to be published to:
/path/to/vendors/bower/jquery/dist
No matter what I do, I still get that error message. I suspect it's a Yii2 issue and not a composer issue but I'm not sure. Anyone got any ideas? Thanks in advance.
// 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();
{
"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"
}
}
}
Upvotes: 12
Views: 35853
Reputation: 5001
This issue comes, because the old assets plugin installed files in vendor/bower
and vendor/npm
, but since composer no longer needs this plugin and installs below vendor/bower-assets
and vendor/npm-assets
.
You only need the following lines in your config
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
That changes the place where youre assets are looking for the @bower and @npm directories.
After this change you can completely remove the composer-asset-plugin
from your require block and the asset-installer-paths
from your extras block.
Bonus: If you like to move the whole vendor-directory you can add
'vendorPath' => dirname(dirname(__DIR__)) . '/includes/vendor'`
to modify the vendor-path to whever place you like. Keep in mind to move your composer.json to this directory too, or consider changing vendor-dir in your composer config
Upvotes: 0
Reputation: 41796
The asset-installer-paths
directive belongs to the Composer plugin fxp/composer-asset-plugin
.
The plugin is required, for this directive to work. But it seems that you are not requiring it in your project repo or globally.
Try a global installation:
composer global require "fxp/composer-asset-plugin:~1.0"
Upvotes: 1
Reputation: 1469
Turns out there's a there's a simple solution: If you want to change the location of your vendor assets then you must follow these simple steps:
include the composer-asset-plugin in your composer.json
file
"require": {
"fxp/composer-asset-plugin": "*"
}
include the composer-asset-plugin directive in your extra config. in your composer.json file:
"extra": {
"asset-installer-paths": {
"npm-asset-library": "../../path/to/vendors/npm",
"bower-asset-library": "../../path/to/vendors/bower"
}
}
add the vendor location to the config section in your composer.json file:
"config": {
"vendor-dir": "../../path/to/vendors"
}
update web/index.php to point to the new vendor location:
require(__DIR__ . '/../../../path/to/vendors/autoload.php');
require(__DIR__ . '/../../../path/to/vendors/yiisoft/yii2/Yii.php');
include a vendorPath definition in your config/web.php:
'vendorPath' => '../../../path/to/vendors',
That should work with the vanilla Yii2 basic template.
Upvotes: 17
Reputation: 29
This works for me:
sudo cp -R bower-asset/* bower
Simply copy all files and folders from bower-asset to bower.
Upvotes: 2