不会。composer archive 默认只打包 composer.json 中 autoload 声明的源码路径(如 src/)及根目录部分文件,vendor/ 从不包含,也不受 --exclude 影响;压缩包内容由 autoload 配置决定,而非排除规则。

archive 命令默认会打包 vendor 吗?
不会。composer archive 默认只打包当前项目目录下 composer.json 中声明的 autoload 覆盖路径(如 "src/"、"lib/"),以及根目录下的常见文件(composer.json、README.md 等)。vendor/ 从不自动包含,也不受 --exclude 影响——它本来就不在候选列表里。
这意味着:想靠 archive 打出“生产可用压缩包”,必须先确保代码已通过 autoload 显式声明,否则连 src/ 都可能被漏掉。
--exclude 参数只接受相对路径,且不支持通配符
--exclude 的路径是相对于项目根目录的,且只能写具体路径名,不能用 **/Tests/ 或 */tests 这类 glob 模式。例如:
composer archive --format=zip --exclude=tests --exclude=docs --exclude=.git --exclude=phpunit.xml
常见误操作:
- 写成
--exclude=tests/(末尾斜杠会导致匹配失败) - 写成
--exclude=./tests(./会被忽略,实际等价于--exclude=tests,但易引发混淆) - 试图排除
node_modules/却忘了它不在 autoload 路径里——其实根本打不进去,排除纯属多余
真正影响压缩包体积的其实是 autoload 配置
压缩包内容由 autoload 决定,不是由 --exclude “删减”出来的。比如:
若 composer.json 中写的是:
"autoload": { "psr-4": { "App\": "src/" } }
那么只有 src/ 下的 PHP 文件会被扫描并加入归档;bin/、config/、migrations/ 这些目录即使存在,也不会被打包——除非你显式加到 autoload.files 或其他 autoload 类型里。
围绕关键发现、作用机制、临床相关性及研究局限性展开讨论。适用于撰写或优化任何生物医学论文的“讨论(Discussion)”部分——包括结果解读、与既往文献关联、阐释意外发现、界定研究局限性,以及撰写结论。当用户输入以下任一指令时也会自动触发该功能: - “write my discussion” - “help me discuss my findings” - “how do I compare to prior studies” - “write the limitations par
所以“极限瘦身”的关键动作是:
- 检查
autoload是否最小化(只包含运行时必需的命名空间和路径) - 把测试、配置、脚本类文件移出 autoload 路径,或改用
autoload-dev(它不影响archive) - 确认
autoload-files没有引入大体积辅助文件(如生成的路由缓存、语言包)
注意 .gitattributes 的 exclude 行为优先级更高
如果项目根目录存在 .gitattributes,且其中包含类似:
tests export-ignore docs export-ignore
那么 composer archive 会直接遵守它,--exclude 参数将被忽略。这是 Git 归档机制的底层行为,Composer 只是调用了 git archive。
验证方式很简单:
git archive --format=tar HEAD | tar -t | grep -E '^(tests|docs)/'
如果输出为空,说明 .gitattributes 已生效;此时再加 --exclude 就是重复劳动。
容易被忽略的一点:CI 环境中若未检出 Git 信息(如 shallow clone 或 zip 下载源码),composer archive 会退回到纯 PHP 扫描逻辑,这时 .gitattributes 完全失效,只认 autoload 和 --exclude ——行为不一致,务必在目标环境中实测。

















