跳到正文
Skillpedia
API 与服务器(后端)8.1k · #12581

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api-bundle-size-limit/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 context
  • api-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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能