@debuffjp/assets

中文文档
0.33.0发布于 2026/11/11MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 9173

Manifest-driven asset loader with preload groups for debuff

原始使用文档
文档目录4 节
  1. Conventions (from the asset compiler)
  2. API
  3. Typed asset ids
  4. Atlases

@debuffjp/assets

Runtime loader for the manifest that debuff generates from your project's assets/ folder. No dependencies.

import { Assets } from "@debuffjp/assets";
import { Sprite } from "@debuffjp/core";

const assets = new Assets(await (await fetch("assets/manifest.json")).json());
await assets.load("default", ({ loaded, total }) => showProgress(loaded / total));

const hero = new Sprite({ frames: assets.frames("hero") }); // [email protected], sliced on its grid
draw.sprite(assets.frame("coin"), x, y); // any image, atlased or not

Conventions (from the asset compiler)

FileAsset idGroup
assets/logo.pnglogodefault
assets/level1/map.jsonlevel1/maplevel1
assets/[email protected]hero (grid 16x24)default

Keep each image within 4096 pixels on a side: a GPU with a smaller texture limit draws a bigger one black, and the CLI warns about it. Spread a long run of frames over several sheets. Before 0.29.3, the CLI didn't warn.

API

  • load(groups?, onProgress?): preload one or more groups
  • fetch(id): lazy-load a single asset; concurrent calls share one request
  • frame(id): { image, x, y, w, h } for draw.sprite; works for atlased and standalone images
  • frames(id): sprite-sheet frames from the name@WxH grid
  • image(id) (standalone images only), json(id), audio(id), text(id), entry(id), has(id)

Typed asset ids

debuff dev, debuff build and npx debuff assets write .debuff/assets.d.ts, which fills the AssetRegistry interface with every asset id, its type and its group. Include that file in tsconfig.json and a misspelt id, an id of the wrong type or an unknown group is a compile error. Without it, ids are plain strings (as before 0.22). AssetId<"image"> and AssetGroup are exported for your own signatures.

Atlases

The CLI packs PNGs into atlases per preload group, in dev and in builds, so a level loads one texture instead of dozens. It's lossless, with padding that prevents edge bleeding. Images over half the atlas size stay standalone. Configure or disable it in debuff.config.ts:

export default defineConfig({ assets: { atlas: { maxSize: 2048, padding: 2, exclude: ["ui/"] } } }); // or atlas: false
  • Errors are AssetError with the asset id and a suggested fix

版本与发布记录

@debuffjp/assets 共发布 56 个版本,首次发布于 2026/10/16;过去 12 个月发布了 56 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.33.0latest2026/11/11今天
0.32.02026/11/074 天前
0.31.12026/11/065 天前
0.31.02026/11/065 天前
0.30.02026/11/056 天前
0.29.22026/11/056 天前

关于 @debuffjp/assets 的常见问题

@debuffjp/assets 是什么?

Manifest-driven asset loader with preload groups for debuff

如何安装 @debuffjp/assets?

在项目目录运行 npm install @debuffjp/assets,或使用 pnpm add / yarn add / bun add。

@debuffjp/assets 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@debuffjp/assets 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@debuffjp/assets 可以商用吗?

@debuffjp/assets 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@debuffjp/assets 的下载量有多少?

根据 npm 官方下载统计,@debuffjp/assets 在 2026/10/12 – 2026/11/10 这 30 天内被下载 9,173 次,日均约 306 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@debuffjp/assets 还在维护吗?

最新版本 0.33.0 发布于 2026/11/11(今天);至今共发布 56 个版本,其中过去 12 个月发布了 56 个;首次发布于 2026/10/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。