Up
Down
Comment
collect
Report
share
RPG MV/MZ引擎的Typescript项目参考配置
这里给出一些关于严格代码质量的配置以及提示,根据使用场景来调整,不需要做到完全相同。
构建步骤:
# 1. 初始化 package.json
npm init -y
npm pkg set type="module"
# 2. 安装 TypeScript、Babel、Rollup 构建工具
npm install -D typescript rollup tslib rimraf @types/node && \
npm install -D @rollup/plugin-typescript && \
npm install -D @rollup/plugin-babel && \
npm install -D @rollup/plugin-terser && \
npm install -D @rollup/plugin-replace && \
npm install -D @babel/core && \
npm install -D @babel/preset-env && \
npm install -D core-js@3 && \
npm install -D @rollup/plugin-node-resolve @rollup/plugin-commonjs
# 2.5 代码类型安全和规范
npm install -g @biomejs/biome
npm install -D neverthrow zod && \
npm install -D typescript typescript-eslint eslint-plugin-unicorn
# 3. 创建目录结构
mkdir src
mkdir dist
{
// ══════════════════════════════════════════
// RPG Maker MV/MZ 兼容性 tsconfig.json
// 目标:Chrome 41+ (NW.js 0.12.x)
// TypeScript 版本:5.4+
// ══════════════════════════════════════════
"compilerOptions": {
// 编译目标
"target": "ES5", // 输出JS版本 - ES5确保最大兼容性
"module": "ESNext", // 模块格式 - 保留ESM让Rollup处理
"lib": [
"ES5", // 基础类型
"ES2015.Promise", // Promise
"ES2015.Collection", // Map/Set/WeakMap/WeakSet
"ES2015.Iterable", // 迭代器协议
"ES2015.Symbol", // Symbol支持
"ES2015.Core", // find/assign/includes等
"DOM", // DOM API
"DOM.Iterable" // DOM集合迭代器
],
"moduleResolution": "bundler", // 模块解析 - 适配打包工具(TS 5.0+)
// 严格类型检查 (strict:true 已包含以下所有,显式列出防止语义变更)
"strict": true, // 严格模式总开关
"noImplicitAny": true, // 禁止隐式any
"strictNullChecks": true, // null/undefined显式处理
"strictFunctionTypes": true, // 函数参数逆变检查
"strictBindCallApply": true, // bind/call/apply参数检查
"strictPropertyInitialization": true, // 类属性必须初始化
"noImplicitThis": true, // 禁止隐式any的this
"useUnknownInCatchVariables": true, // catch变量为unknown
"alwaysStrict": true, // 输出"use strict"
// 额外安全检查 (Rust风格)
"noUncheckedIndexedAccess": true, // 索引访问返回 T|undefined
"noPropertyAccessFromIndexSignature": false, // true: 强制使用obj["key"],提高代码明确性; false: 允许使用obj.key,提高代码简洁性
"exactOptionalPropertyTypes": true, // 区分undefined值和属性缺失
// 代码质量
"noUnusedLocals": true, // 禁止未使用的局部变量
"noUnusedParameters": true, // 禁止未使用的参数(用_前缀忽略)
"noImplicitReturns": true, // 所有代码路径必须有返回值
"noFallthroughCasesInSwitch": true, // switch必须break/return
"noImplicitOverride": true, // 覆盖父类方法需override关键字
"allowUnreachableCode": false, // 禁止不可达代码
"allowUnusedLabels": false, // 禁止未使用的标签
// 增强选项
"noErrorTruncation": true, // 显示完整错误信息不截断
"stripInternal": true, // 从.d.ts移除@internal标记的API
"noUncheckedSideEffectImports": true, // 检查副作用导入是否存在(TS 5.4+)
// 构建行为
"noEmitOnError": true, // 有错误时不输出文件
"esModuleInterop": true, // 兼容CommonJS默认导入
"allowSyntheticDefaultImports": true, // 允许默认导入无default的模块
"skipLibCheck": true, // 跳过.d.ts类型检查(加速编译)
"forceConsistentCasingInFileNames": true, // 强制文件名大小写一致
// 输出配置
"outDir": "./dist", // 输出目录
"rootDir": "./src", // 源代码根目录
"sourceMap": true, // 生成.js.map调试映射
"declaration": true, // 生成.d.ts类型声明
"declarationMap": true, // 生成.d.ts.map支持跳转源码
"removeComments": false, // 保留注释(让打包工具处理)
"preserveConstEnums": true, // 保留const enum对象
// 模块与路径
"allowJs": true, // 允许编译JavaScript文件
"checkJs": false, // 不检查JavaScript文件类型
"resolveJsonModule": true, // 允许导入JSON模块
"baseUrl": ".", // 路径别名基准目录
"paths": {
"@/*": ["src/*"] // 路径别名(需打包工具同步配置)
},
"typeRoots": ["./typings", "./node_modules/@types"] // 类型声明查找目录
},
"include": ["src/**/*"], // 编译src下所有文件
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"] // 排除目录和测试文件
}DeclarationAll articles on this site, unless otherwise indicated or marked, are original publications of this site. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of the author. If the content of this site infringes upon the legitimate rights and interests of the original author, please contact us for processing: DMCA Report
Follow Us














This uploader feels lonely