Composer 本身没有 archive 命令,所谓“archive 配置”仅在 Satis 私有仓库构建和 Packagist dist 包生成时生效;本地 composer.json 中的 "archive" 字段对 install/update 完全无效。

Composer 本身没有 archive 命令,所谓 “archive 配置” 只在两个地方真正起作用:Satis 私有仓库配置 和 Packagist 的 dist 包构建流程。你在 composer.json 里写 "archive": {...},对本地执行 composer install 或 composer update 完全无效。
为什么你看到的 archive 配置不生效
很多人在 composer.json 根级加了 "archive": { "exclude": ["/tests"] },然后运行 composer archive —— 结果报错 Command "archive" is not defined。这不是配置错了,是命令根本不存在。Composer 官方从未实现过这个子命令。所有“能用”的案例,要么是装了第三方插件(如 hirak/php-archive),要么是项目里自定义了 "scripts": { "archive": "..." }。这些行为不受 Composer 控制,升级或卸载插件后立刻失效。
archive 配置只在 Satis 和 Packagist 中生效
当你用 Satis 构建私有包仓库,或把包发布到 Packagist,它们在生成 dist 归档包(zip/tar)时,会读取你包的 composer.json 中的 archive 字段。这是唯一官方支持的使用场景:
-
"archive": { "format": "zip", "directory": "dist", "skip-dev": true }—— Satis 会按此生成压缩包并存到dist/目录 -
"archive": { "exclude": ["/tests", "/docs"] }—— Packagist 构建 dist 包时会跳过这些路径(仅对 Git tracked 文件有效) - 路径必须以
/开头,比如"/tests",否则匹配失败;不支持通配符(**或*.md) - 该配置不影响 GitHub “Download ZIP”,那个走的是
git archive,只认.gitattributes中的export-ignore
想真正控制归档内容,优先用 .gitattributes
比依赖 composer.json 的 archive.exclude 更可靠的方式,是在项目根目录建 .gitattributes 文件。所有基于 git archive 的分发(GitHub ZIP、GitLab、Satis、Packagist)都原生支持它:
使用ydata-profiling(前身为pandas-profiling)生成全面的数据质量报告,包含相关性分析、缺失值模式和基数检测。导出交互式HTML仪表板和JSON摘要。
/.gitattributes export-ignore /tests export-ignore /Tests export-ignore /phpunit.xml export-ignore /README.md export-ignore
注意:export-ignore 只对已提交(tracked)的文件生效;未提交的临时文件(如 .env、storage/logs/)得靠 git ignore 先管住,否则它们根本不会出现在 git archive 输出里,也就不受任何配置影响。
别指望 composer archive 打出可运行包
即使你通过插件“跑通”了 composer archive,它默认只打包源码,不含 vendor/,也不执行 autoload 优化。真要部署,正确路径是:
- 先运行
composer install --no-dev --optimize-autoloader - 再用系统命令打包:
tar -czf myapp.tar.gz .或zip -r myapp.zip . -x "node_modules/*" ".git/*" - 打包前务必确认
composer.lock已提交,且vendor/下没残留未跟踪的开发文件
最易被忽略的一点:归档后不验证内容,就直接上传——建议解压后立刻执行 find . -name ".env" -o -name "*.log" -o -path "./.git*" | head -5,扫一眼有没有漏掉的敏感路径。

















