PHP Composer - 设置供应商目录
PHP Composer - set vendor directory
我在为 Yii2 应用程序配置供应商路径时遇到问题。我在从 Yii2 基本应用程序模板获得的 composer.json 文件中添加了几行。我只想更改供应商资产的位置。
以下是我对文件所做的更改,但出现此错误:
The file or directory to be published does not exist: /path/to/app/vendor/bower/jquery/dist
但是我希望将特定资产发布到:
/path/to/vendors/bower/jquery/dist
无论我做什么,我仍然会收到该错误消息。我怀疑这是 Yii2 问题而不是作曲家问题,但我不确定。有人有什么想法吗?提前致谢。
文件...
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"
}
}
}
asset-installer-paths
directive 属于 Composer 插件 fxp/composer-asset-plugin
。
插件是必需的,这个指令才能工作。但似乎您的项目回购或全局不需要它。
尝试全局安装:
composer global require "fxp/composer-asset-plugin:~1.0"
事实证明有一个简单的解决方案:如果您想更改供应商资产的位置,则必须执行以下简单步骤:
在您的 composer.json
文件中包含 composer-asset-plugin
"require": {
"fxp/composer-asset-plugin": "*"
}
在您的额外配置中包含 composer-asset-plugin 指令。在您的 composer.json 文件中:
"extra": {
"asset-installer-paths": {
"npm-asset-library": "../../path/to/vendors/npm",
"bower-asset-library": "../../path/to/vendors/bower"
}
}
将供应商位置添加到 composer.json 文件的配置部分:
"config": {
"vendor-dir": "../../path/to/vendors"
}
更新 web/index.php 以指向新的供应商位置:
require(__DIR__ . '/../../../path/to/vendors/autoload.php');
require(__DIR__ . '/../../../path/to/vendors/yiisoft/yii2/Yii.php');
在您的 config/web 中包含 vendorPath 定义。php:
'vendorPath' => '../../../path/to/vendors',
这应该适用于 vanilla Yii2 基本模板。
这对我有用:
sudo cp -R bower-asset/* bower
只需将所有文件和文件夹从 bower-asset 复制到 bower。
我在为 Yii2 应用程序配置供应商路径时遇到问题。我在从 Yii2 基本应用程序模板获得的 composer.json 文件中添加了几行。我只想更改供应商资产的位置。
以下是我对文件所做的更改,但出现此错误:
The file or directory to be published does not exist: /path/to/app/vendor/bower/jquery/dist
但是我希望将特定资产发布到:
/path/to/vendors/bower/jquery/dist
无论我做什么,我仍然会收到该错误消息。我怀疑这是 Yii2 问题而不是作曲家问题,但我不确定。有人有什么想法吗?提前致谢。
文件...
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"
}
}
}
asset-installer-paths
directive 属于 Composer 插件 fxp/composer-asset-plugin
。
插件是必需的,这个指令才能工作。但似乎您的项目回购或全局不需要它。
尝试全局安装:
composer global require "fxp/composer-asset-plugin:~1.0"
事实证明有一个简单的解决方案:如果您想更改供应商资产的位置,则必须执行以下简单步骤:
在您的
composer.json
文件中包含 composer-asset-plugin"require": { "fxp/composer-asset-plugin": "*" }
在您的额外配置中包含 composer-asset-plugin 指令。在您的 composer.json 文件中:
"extra": { "asset-installer-paths": { "npm-asset-library": "../../path/to/vendors/npm", "bower-asset-library": "../../path/to/vendors/bower" } }
将供应商位置添加到 composer.json 文件的配置部分:
"config": { "vendor-dir": "../../path/to/vendors" }
更新 web/index.php 以指向新的供应商位置:
require(__DIR__ . '/../../../path/to/vendors/autoload.php'); require(__DIR__ . '/../../../path/to/vendors/yiisoft/yii2/Yii.php');
在您的 config/web 中包含 vendorPath 定义。php:
'vendorPath' => '../../../path/to/vendors',
这应该适用于 vanilla Yii2 基本模板。
这对我有用:
sudo cp -R bower-asset/* bower
只需将所有文件和文件夹从 bower-asset 复制到 bower。