mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 14:53:32 +08:00
- 修改 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 适配代码
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
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: {
|
||
/** 所有依赖都打进 bundle(LLRT 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"],
|
||
}),
|
||
];
|