Yii2:使用fxp资产插件还是asset-packagist?

huangapple go评论51阅读模式
英文:

Yii2: use fxp assets plugin or asset-packagist?

问题

似乎 Yii2 在使用 asset-packagist.org 方法和旧的 fxp assets 插件之间存在一些未解决的冲突。我现在正在处理一个项目,打算使用 asset-packagist。所有设置看起来都没问题,但 Yii2 似乎忽视了所有设置,坚持使用一个不存在的 bower 目录。使用 asset-packagist 方法,这个目录被称为 bower-asset。

设置如下:为了使其工作,我们在 common/config/base.php 中使用以下配置:

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

...并在 composer.json 中设置:

"repositories": [
    {
        "type": "composer",
        "url": "https://asset-packagist.org"
    }
],

然而,这并没有帮助,仍然出现以下错误:

要发布的文件或目录不存在:
C:\....common\config/../../vendor/bower/semantic/dist

还尝试了在 composer.json 中关闭 fxp(fxp-asset):

"config": {
    "fxp-asset": {
        "enabled": false
    }
},

也尝试了以下命令:

composer global remove fxp/composer-asset-plugin --no-plugins

仍然没有变化。

注意:该项目在 Linux 上开发,我现在正在尝试在 Windows 10 和本地的 XAMPP 上打开它。如果与 Windows 相关,请随时告诉我。

英文:

Seems like yii2 has some unresolved conflict between
using the asset-packagist.org method, or the older
fxp assets plugin.
I am now working with a project, intended to use the
asset-packagist. All settings appear OK, but Yii2 seems to ignore
it all and insist on using a bower directory that does not exist.
Using the asset-packagist method, this directory is called bower-asset.

The settings: To make this work, we use (in common/config/base.php):

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

...and in composer.json we set:

 "repositories": [
{
    "type": "composer",
    "url": "https://asset-packagist.org"
}
],

That does not help, however, still getting the error:

 The file or directory to be published does not exist: 
 C:\....common\config/../../vendor/bower/semantic/dist

Also tried to switch fxp off with (in composer.json):

 "config": {
"fxp-asset": {
        "enabled": false
    }
  },

Also tried command:

 composer global remove fxp/composer-asset-plugin  --no-plugins

Same thing.

Note: The project was developed in Linux, I am now trying open it in Windows 10 and XAMPP on localhost. Feel free to tell me if Windows-related.

答案1

得分: 2

为了使这个工作正常,我不得不选择fxp-plugin,并放弃asset-packagist的方式(就我目前的知识来说,它根本不起作用),像这样:

  • 从composer.json的repositories部分中删除对"asset-packagist.org"的引用(在我的情况下,我删除了整个repositories部分:
"repositories": [
    {
        "type": "composer",
        "url": "https://asset-packagist.org"
    }
],
  • 安装最新的composer fxp-plugin,目前是1.4.6版本:
composer global require "fxp/composer-asset-plugin:~1.4.6"
  • 从common/config/base.php中删除@bower -> bower-asset(以及npm的别名)。
  • 然后,如果你将vendor中的bower-asset文件夹重命名为"bower",它就会找到正确的路径。但你不应该更改vendor文件夹中的任何内容,而是将以下"fxp-asset"部分添加到composer.json的"config"中:
"config": {
    "process-timeout": 1800,
    "fxp-asset": {
        "installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        }
    }
}
  • 然后删除vendor文件夹,删除Composer.lock文件,并运行composer install
英文:

To get this to work, I had to choose the fxp-plugin, and to let go of the asset-packagist way (it simply does not work, given the knowledge I have at this point), like this:

  • Removed the reference to asset-packagist.org from repositories section in composer.json (in my case I removed the whole repositories section.:

> "repositories": [
> {
> "type": "composer",
> "url": "https://asset-packagist.org"
> }
> ],

  • Install the latest composer fxp-plugin, currently 1.4.6:

> composer global require "fxp/composer-asset-plugin:~1.4.6"

  • Removed the @bower -> bower-asset (and those for npm) aliases in common/config/base.php.
  • Then, now it finds the correct path if you rename the bower-asset folder in vendor to "bower". But you should never change anything in the vendor folder, instead, add this fxp-asset section to "config" in composer.json:

> "config": {
> "process-timeout": 1800,
> "fxp-asset":{
> "installer-paths": {
> "npm-asset-library": "vendor/npm",
> "bower-asset-library": "vendor/bower"
> }
> }
> }

  • Then remove the vendor folder, remove the Composer.lock file and run composer install .

huangapple
  • 本文由 发表于 2020年1月6日 19:19:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611182.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定