api-bundle-size-limit
它能做什么
这项技能帮助你的 AI 修改 Webiny API 构建的体积上限。适合 API 构建因包体积超过默认上限而失败的开发者。
适用场景
- ✓当你的 Webiny API 构建因资源体积上限错误而失败的时候。
- ✓当你的 API 包超过默认的 4.5 MB 上限的时候。
- ✓当你希望对 API 包执行更严格的体积上限的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api-bundle-size-limit/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Webiny 构建因资源体积上限错误而失败。请把 API 包的上限提高到 6 MB。”
每周 5 个新技能,1 分钟读完。
工作原理
技能演示如何在 Webiny 配置文件中添加一项设置,并以字节为单位填写大小。它还解释如何阅读构建错误信息。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
API Bundle Size Limit
TL;DR
The Infra.Api.MaxBundleSize extension enforces a maximum size on the built API Lambda bundle. The default limit is 4.5 MB. If the bundle exceeds the limit the build fails with a clear error; add the extension to webiny.config.tsx to raise (or lower) it.
Default Behavior
By default Webiny enforces a 4.5 MB limit on the API Lambda bundle (handler.mjs). If the built output exceeds this, the build fails:
error Build errors:
× asset size limit: The following asset(s) exceed the recommended size limit (4.5 MiB).
× entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (4.5 MiB).
error build failed
Raising the Limit
Add Infra.Api.MaxBundleSize to webiny.config.tsx with size in bytes:
// webiny.config.tsx
import { Infra } from "webiny/extensions";
export const Extensions = () => (
<>
{/* Raise the API bundle size limit to 6 MB */}
<Infra.Api.MaxBundleSize size={6 * 1024 * 1024} />
</>
);
Common byte values:
| MB | Bytes expression | Exact bytes |
|---|---|---|
| 4.5 | Math.round(4.5 * 1024 * 1024) |
4718592 (default) |
| 5 | 5 * 1024 * 1024 |
5242880 |
| 6 | 6 * 1024 * 1024 |
6291456 |
| 8 | 8 * 1024 * 1024 |
8388608 |
| 10 | 10 * 1024 * 1024 |
10485760 |
How It Works
The extension sets the WEBINY_INFRA_API_MAX_BUNDLE_SIZE environment variable (in bytes) which is read by the API bundler (@webiny/build-tools) at build time. The WEBINY_INFRA_ prefix ensures the variable is not automatically forwarded to the Lambda function's runtime environment.
Lowering the Limit
You can also enforce a stricter limit to catch bundle regressions early:
{
/* Enforce a strict 3 MB limit */
}
<Infra.Api.MaxBundleSize size={3 * 1024 * 1024} />;
Quick Reference
| Task | Snippet |
|---|---|
| Raise to 6 MB | <Infra.Api.MaxBundleSize size={6 * 1024 * 1024} /> |
| Raise to 10 MB | <Infra.Api.MaxBundleSize size={10 * 1024 * 1024} /> |
| Restore default (4.5 MB) | Remove the extension |
| Convert MB to bytes | Math.round(N * 1024 * 1024) |
Related Skills
infra-env-var-- setting arbitrary environment variables in the project contextapi-lambda-function-- adding custom Lambda functions to the API
常见问题
默认上限是多少?
API Lambda 包的默认上限是 4.5 MB。
这项设置使用什么单位?
使用字节,因此 6 MB 应写为 6 × 1024 × 1024 字节。
我可以把上限设得更严格吗?
可以。技能说明,你可以设置更低的上限来执行更严格的体积限制。
详情
作者的原始描述
Covers how to configure the maximum allowed size of the Webiny API Lambda bundle using the Infra.Api.MaxBundleSize extension in webiny.config.tsx. Use when a project's API bundle exceeds the default 4.5 MB limit or when you want to enforce a stricter limit. Handles the extension syntax, byte calculations, and interpreting the build error message.
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12581
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。