web-font/tsdown.config.ts
崮生(子虚) dc1ee66fe3 修复 temp-cleaner 在 LLRT 上的 unlink 兼容性问题
- 修改 interface.ts: 接受 options.unlink 和 options.rm 作为 FS 适配器的可配置方法
- 修改 llrt.ts: 使用箭头函数 (path) => fs.rm(path) 避免 this 绑定问题
- 修改 app.ts: 通过 __RUNTIME__ 条件编译,仅在 LLRT 运行时引入 llrt.ts
- 修改 tsdown.config.ts: format 从字符串数组改为字符串类型,添加 as const
- 修改 tsconfig.node.json: 添加 node 类型支持
- 新增 backend/global.d.ts: 声明 __RUNTIME__ 全局变量类型
- 修改 .gitignore: 添加 dist_backend_node 目录
- 修改 build-backend.ts: 支持 Node.js 版本构建输出到 dist_backend_node

修复问题:
- LLRT fs/promises 没有 unlink 方法,只有 rm 方法
- CJS 格式不支持 top-level await,改用 IIFE + require
- 条件编译避免 Node.js 版本包含不必要的 LLRT 适配代码
2026-08-15 07:02:22 +08:00

51 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineConfig } from "tsdown";
import { readFileSync } from "node:fs";
/** 构建期读取 package.json 版本号,注入为运行时常量(避免运行时读文件 + LLRT 无 __filename 问题) */
const packageVersion = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
const shared = {
format: "cjs",
clean: true,
sourcemap: true,
outDir: "dist_backend",
outputOptions: {
/** 禁用代码拆分确保单文件输出tsdown 默认会拆分大依赖为 chunk */
codeSplitting: false,
},
deps: {
/** 所有依赖都打进 bundleLLRT scratch 镜像无 node_modules */
alwaysBundle: [/.*/],
},
} as const;
export default [
defineConfig({
...shared,
/** LLRT 构建 */
define: {
PACKAGE_VERSION: JSON.stringify(packageVersion),
__RUNTIME__: JSON.stringify("llrt"),
},
entry: ["backend/app.ts"],
}),
defineConfig({
...shared,
/** Node.js 构建(用于本地开发测试) */
define: {
PACKAGE_VERSION: JSON.stringify(packageVersion),
__RUNTIME__: JSON.stringify("node"),
},
/** 第二个配置不 clean避免清掉第一个的输出 */
clean: false,
entry: ["backend/app.ts"],
outDir: "dist_backend_node",
}),
defineConfig({
...shared,
/** 第二个配置不 clean避免清掉第一个的输出 */
clean: false,
entry: ["基准测试_llrt.ts"],
}),
];