@cocos/tfig

中文文档
3.3.4发布于 2025/03/18MITTypeScriptCommonJS近 30 天下载 2569

Yet another tool to generate .d.ts bundle.

原始使用文档
文档目录3 节
  1. Getting started
  2. How-to
  3. Comman line arguments

Yet another tool to generate bundled .d.ts.

The tool is essentially used in https://github.com/cocos-creator/engine .

For instance, this tool bundles

declare module "index" {
    export * from "math";
}
declare module "math" {
    export { Vec2 } from "math/vec2";
    export { Vec3 } from "math/vec3";
    import * as utils from "math/utils";
    export { utils };
}
declare module "math/vec2" {
    export class Vec2 {}
}
declare module "math/vec3" {
    export class Vec3 {}
}
declare module "math/utils" {
    export function sin();
    export function cos();
}

into

declare module "my-module" {
    export class Vec2 {}
    export class Vec3 {}
    namespace utils {
        export function sin(n: number);
        export function cos(n: number);
    }
}

Getting started

How-to

Install this package, such as, from npm:

npm install -g tfig

Compile your TypeScript project, make sure to let tsc generate a single declaration file. eg. Have the option outFile in tsconfig.json:

{
    outFile: "out.js",
}

Bundle:

gift-cli --input "out.d.ts" --root "name-of-the-root-module-in-your-project" --output "path-to-your-output-dir" --name "your-bundle-name"

Comman line arguments

input

Path to the unbundled *.d.ts file. In general, this file this produced by tsc.

root

Name of the root module to bundle.

output

Output path. Can be directory or file.

name

The generated module name.

版本与发布记录

@cocos/tfig 共发布 2 个版本,首次发布于 2024/04/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.3.4latest2025/03/181.6 年前
3.3.32024/04/192 年前

关于 @cocos/tfig 的常见问题

@cocos/tfig 是什么?

Yet another tool to generate .d.ts bundle.

如何安装 @cocos/tfig?

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

@cocos/tfig 支持 TypeScript 吗?

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

@cocos/tfig 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cocos/tfig 可以商用吗?

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

@cocos/tfig 的下载量有多少?

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

@cocos/tfig 还在维护吗?

最新版本 3.3.4 发布于 2025/03/18(1.6 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/04/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。