funding字段是Composer中用于声明项目资金支持方式的可选配置,位于composer.json根层级,格式为包含type和url的对象数组,常见type包括github、patreon、open_collective、tidelift和custom,填写后可在Packagist页面展示赞助入口,帮助开发者获得经济支持,促进开源生态可持续发展。

在 composer.json 文件中,funding 字段用于声明项目的资金支持方式,帮助开发者或维护者获得经济支持。这个字段不会影响代码运行,但对开源生态的可持续发展有重要意义。
funding 是 Composer 提供的一个可选字段,允许项目维护者列出可用于资助该项目的平台或链接。当其他开发者使用你的包时,他们可以通过此信息了解如何支持你。
该字段出现在 composer.json 的根层级,格式为一个对象数组,每个对象包含类型(type)和 URL(url)两个键。
基本结构如下:
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/用户名"
},
{
"type": "patreon",
"url": "https://www.patreon.com/用户名"
},
{
"type": "open_collective",
"url": "https://opencollective.com/项目名"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/平台名/项目名"
},
{
"type": "custom",
"url": "https://你的网站/donate"
}
]
常见 type 值包括:
假设你在 GitHub 上维护一个开源库,并开通了赞助功能,可以这样写:
{
"name": "your-vendor/your-package",
"description": "A sample package",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Your Name",
"email": "you@example.com"
}
],
"require": {},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/your-github-username"
},
{
"type": "custom",
"url": "https://paypal.me/yourpaypal"
}
]
}
这样,当你发布到 packagist.org 后,页面上会显示“Sponsor”按钮,点击即可跳转到你的赞助链接。
这个字段的主要用途是:
虽然不是必填项,但如果你希望获得社区支持,建议合理填写。
基本上就这些。只要按规范写好 type 和 url,就能让别人更容易支持你的开源工作。不复杂但容易忽略。
以上就是composer.json中的funding字段怎么填写_解析composer.json funding字段的用途及填写方法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号