【问题标题】:composer custom install directory - root作曲家自定义安装目录 - 根
【发布时间】:2017-11-04 00:17:35
【问题描述】:

我们正在尝试使用 composer 来处理 wordpress 网站的依赖关系。我想将 wordpress 本身包含在这些依赖项中。我正在尝试将 wordpress 安装到项目的根目录。所有其他插件等都根据安装程序路径正确安装..

我尝试过使用 fancyguy/webroot-installer,但这会擦除安装包的目录 还尝试了 mnsami/composer-custom-directory-installer,但这也会擦除目录。

我在根目录中有一些我不想删除的文件 - 例如 composer.json 一个,.tfignore 等等。

是我必须让它安装到 /vendor 然后运行安装后脚本将其移动到我想要的位置的唯一选择吗?还是我缺少另一个选项

这是我为 webroot-installer 尝试过的一个

{
  "name": "the/name",
  "description": "description",
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
        "name": "wordpress",
        "type": "webroot",
        "version": "4.7.5",
        "dist": {
          "type": "zip",
          "url": "https://github.com/WordPress/WordPress/archive/4.7.5.zip"
        },
        "require": {
          "fancyguy/webroot-installer": "1.0.0"
        }
      }
    }
  ],
  "require-dev": {
    "wpackagist-plugin/query-monitor": "2.13.4",
    "wordpress": "4.7.5",
    "fancyguy/webroot-installer": "1.0.0"
  },
  "require": {
    "wpackagist-plugin/advanced-custom-fields": "4.4.11",
    ...etc
  },
  "extra": {
    "webroot-dir": ".",
    "webroot-package": "wordpress",
    "installer-paths": {
      "library/plugins/{$name}": [ "type:wordpress-plugin" ]
    }
  },
  "scripts": { ...}
}

这是使用 composer-custom-directory-installer 的 composer.json。

{
  "name": "the/name",
  "description": "description",
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
        "name": "wordpress",
        "type": "library",
        "version": "4.7.5",
        "dist": {
          "type": "zip",
          "url": "https://github.com/WordPress/WordPress/archive/4.7.5.zip"
        }
      }
    }
  ],
  "require-dev": {
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "wordpress": "4.7.5"
  },
  "require": {
    "wpackagist-plugin/advanced-custom-fields": "4.4.11",
    ...etc
  },
  "extra": {
    "installer-paths": {
      "library/plugins/{$name}": [ "type:wordpress-plugin" ],
      "./": [ "wordpress" ]
    }

  },
  "scripts": { ... }
}

【问题讨论】:

    标签: wordpress composer-php


    【解决方案1】:

    我相信这就是作曲家安装程序的工作方式。从我所做的阅读来看,它会删除旧文件以确保没有任何版本的交叉污染。它不像 git checkout/merge 可以处理差异,而是在需要时进行全新安装(缓存类型的东西)。

    我建议不要将您正在创作的任何文件保存在您正在安装东西的同一文件夹中,而是采用将所有内容安装并编译到分发文件夹中的方法。

    利用 webpack 或 gulp 等工具,以及 NPM 和 composer 来处理您的所有编译,并将您的分发文件夹保留为可以被吹走和复制的东西。它增加了一些开销,但允许所有工具进行交互而不会导致文件丢失。

    例如,我的典型存储库如下所示。有了所有不同的工具,dist 完全被 gitignored,但是 composer 和 build 工具编译到它里面。如果我想 FTP 或使用 CI/CD,我可以从那里开始,但我有一个干净的文件夹,它永远不会存储,并且在我运行工具后包含整个项目。

    /dist
    /src (where any files I'm authoring reside)
    composer.json
    package.json
    gulpfile.js
    etc...
    

    对此进行快速更新。一直在自己身边玩。似乎作曲家安装程序的扩展版本不会安装在其他目录之上。我最终做了以下似乎每次都有效的事情(但仍然需要通过部署进行测试)

    "extra": {
        "installer-types": ["cms-core"],
        "installer-paths": {
            "public/wp": ["type:cms-core"],
            "public/wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
            "public/wp-content/themes/{$name}/": ["type:wordpress-theme"]
        }
    },
    "repositories":[
        {
            "type": "composer",
            "url": "https://wpackagist.org"
        },
        {
            "type": "package",
            "package": {
                "name": "wordpress",
                "type": "cms-core",
                "version": "4.7.5",
                "dist": {
                    "type": "zip",
                    "url": "https://github.com/WordPress/WordPress/archive/4.7.5.zip"
                }
            }
        }
    ],
    "require": {
        "composer/installers": "^1.3",
        "oomphinc/composer-installers-extender": "^1.1",
        "wpackagist-plugin/wordpress-seo": "^4.8",
        "wordpress": "^4.7"
    },
    "scripts": {
        "post-update-cmd": [
            "cp -R public/wp/ public && rm -rf public/wp"
        ]
    }`
    

    【讨论】:

      【解决方案2】:

      对于任何尝试将 Wordpress 与 Composer 一起使用的新访问者,请查看 https://github.com/johnpbloch/wordpress 以了解使用自定义 Composer 安装程序的实施。完整的细节和例子可以在https://composer.rarst.net/找到,但它的要点是:

      composer.json:

      {
          "name"        : "my/wordpress-project",
          "description" : "Test project for WordPress stack via Composer",
          "type"        : "project",
          "repositories": [
              {
                  "type": "composer",
                  "url" : "https://wpackagist.org"
              }
          ],
          "config"      : {
              "vendor-dir": "wp-content/vendor"
          },
          "require"     : {
              "johnpbloch/wordpress" : ">=5",
              "wpackagist-plugin/a-fresher-cache" : "*",
              "wpackagist-plugin/core-control" : "*",
              "wpackagist-plugin/monster-widget" : "*",
              "wpackagist-plugin/theme-check" : "*",
              "wpackagist-plugin/user-switching" : "*",
              "wpackagist-plugin/wcm-user-language-switcher" : "*"
          },
          "extra"       : {
              "installer-paths" : {
                  "wp-content/plugins/{$name}/": ["type:wordpress-plugin"]
                  "wp-content/themes/{$name}/": ["type:wordpress-theme"]
              }
      
              "wordpress-install-dir": "wp"
          }
      }
      

      这会将 Wordpress 安装到 /wp 文件夹中。您将需要修改您的 .htaccess 以适合,详情如下:https://wordpress.org/support/article/giving-wordpress-its-own-directory/

      <IfModule mod_rewrite.c>
          RewriteEngine on
          RewriteCond %{HTTP_HOST} ^(www.)?example.com$
          RewriteCond %{REQUEST_URI} !^/wp/
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ /wp/$1
          RewriteCond %{HTTP_HOST} ^(www.)?example.com$
          RewriteRule ^(/)?$ wp/index.php [L]
      </IfModule>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-21
        • 2019-09-08
        • 1970-01-01
        • 2017-03-13
        • 2021-08-07
        • 2017-08-13
        • 2017-04-07
        • 2014-02-26
        相关资源
        最近更新 更多