构建与分发
Estimated reading time: 4 minutes本文介绍 maplebirchFramework 的构建工具链、构建命令和打包流程。
构建工具链
构建命令
Rspack 配置
入口与输出
输出配置为 window 类型的库,导出名为 maplebirch:
这意味着打包后的代码会将 MaplebirchCore 实例挂载到 window.maplebirch。
TypeScript 编译
使用 Rspack 内置的 SWC loader 编译 TypeScript:
- 目标:
> 0.5%, not dead, not ie 11 - 支持
.twee文件作为原始文本资源(?raw查询参数)
开发服务器
开发服务器运行在端口 5678,提供以下功能:
- 静态文件服务(
game/目录) /modList.json端点:自动扫描game/mods/下的.zip文件并列出/{name}-{version}.mod.zip端点:动态创建 mod zip 文件
Tip
开发时需要在项目根目录放置 game/index.html(游戏文件),开发服务器会自动提供热重载的 mod 文件。
类型声明生成
tsup 配置生成仅类型声明文件:
生成的 maplebirch.d.ts 包含框架所有公开 API 的类型定义,供依赖框架的 Mod 开发者使用。
打包流程
ELK not loaded. Ensure /elk.bundled.js is loaded before the app.
最终生成的 .mod.zip 文件包含:
dist/inject_early.js— 编译后的框架代码dist/maplebirch.d.ts— TypeScript 类型声明boot.json— 由package.json中的scml字段生成- 其他必要文件
boot.json 生成
boot.json 从 package.json 的 scml 配置段自动生成:
项目结构
SCML-DOL-maplebirchFramework
src
main.ts# 入口文件
core.ts# MaplebirchCore 核心类
constants.ts# 常量定义
utils.ts# 工具函数
services# 服务层
EventEmitter.ts
GUIControl.ts
IndexedDBService.ts
LanguageManager.ts
Logger.ts
ModuleSystem.ts
modules# 功能模块
AddonPlugin.ts
Audio.ts
Character.ts
Combat.ts
Dynamic.ts
NamedNPC.ts
ToolCollection.ts
Variables.ts
database# 数据库相关
types# TypeScript 类型定义
scripts# 构建脚本
rspack.config.ts# Rspack 配置
tsup.config.ts# tsup 配置
tsconfig.json# TypeScript 配置
package.json# 项目配置
