composer没有archive命令,执行composer archive --format=zip必报“command 'archive' is not defined”;正确做法是先运行composer install --no-dev --optimize-autoloader,再用zip/tar手动打包并显式排除无关文件。

composer archive --format=zip 根本不工作
执行 composer archive --format=zip 必然报错:Command "archive" is not defined。这不是你漏装插件或权限不对,而是 Composer 官方自 2.0 起就从未发布过 archive 命令——源码里没有注册类,composer list 里查不到,文档中也无记载。所有“能跑通”的案例,要么是本地误装了已废弃的第三方插件(如 2018 年停更的 composer-archive-plugin),要么是把 git archive 命令记混了。
真正生成 zip 包的跨平台方案
想得到一个解压后能在 Linux/macOS/Windows 上部署运行的 zip 包,必须分两步:先准备干净的 vendor/,再用系统命令打包。关键不是“用什么工具”,而是“排除什么、保留什么”。
围绕关键发现、作用机制、临床相关性及研究局限性展开讨论。适用于撰写或优化任何生物医学论文的“讨论(Discussion)”部分——包括结果解读、与既往文献关联、阐释意外发现、界定研究局限性,以及撰写结论。当用户输入以下任一指令时也会自动触发该功能: - “write my discussion” - “help me discuss my findings” - “how do I compare to prior studies” - “write the limitations par
-
composer install --no-dev --optimize-autoloader:这步必须在打包前执行,它生成扁平化 autoload map,去掉phpunit等 dev-only 包,且让require加载更快 - Linux/macOS:用
zip -r release.zip . -x ".git/*" "node_modules/*" "tests/*" ".env" "*.log" - Windows PowerShell:用
Compress-Archive -Path . -DestinationPath release.zip -Exclude ".git", "node_modules", "tests", ".env" - CI/CD 或多平台统一:写进
composer.json的scripts段,例如:"archive:zip": "zip -r release.zip . -x \"node_modules/*\" \".git/*\" \"tests/*\" \".env\"",然后运行composer run archive:zip
为什么不能依赖 .gitattributes export-ignore
.gitattributes 中的 export-ignore 规则只对 git archive 生效,对 zip -r、tar -czf 或任何其他压缩命令完全无效。而且它难调试、易漏配——比如写了 .env export-ignore,但忘了 .env.example;写了 docs/** export-ignore,但 docs/api/index.html 仍可能被包含。不如直接在打包命令里用 -x 显式列出要排除的路径,看得见、改得快、CI 里一跑就知对错。
zip 包名和结构容易出问题的地方
用 zip -r 打包时,当前目录名会成为 zip 内顶层目录。如果不在项目根目录执行,或者路径带 ../,解压后会出现冗余父级目录(如 ../myapp/src/),导致 autoload.php 找不到。务必确认:
- 在项目根目录(即含
composer.json的目录)下执行打包命令 - 不要用
zip -r ../release.zip .这类写法,避免路径跳转 - 验证包内容:解压后进目录,运行
php -r "require 'vendor/autoload.php'; echo 'OK';"—— 这比任何“打包成功”提示都管用










