
tsconfig.json
、tsconfig.app.json
和tsconfig.node.json
通常用于不同场景的配置分离,它们的主要区别如下:tsconfig.json
extends
被其他配置继承tsc
命令时,默认会读取此文件include: ["src/**/*"]
)
{
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
tsconfig.app.json
tsconfig.json
的基础配置lib: ["DOM", "ESNext"]
)jsx: "react-jsx"
)src/
)
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "ESNext",
"jsx": "react-jsx"
},
"include": ["src"]
}
tsconfig.node.json
tsconfig.json
的基础配置@types/node
类型)module: "CommonJS"
或NodeNext
)vite.config.ts
、scripts/
)
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2020",
"lib": ["ESNext"],
"module": "NodeNext",
"types": ["node"]
},
"include": ["vite.config.ts", "scripts/**/*"]
}
维度 | tsconfig.json | tsconfig.app.json | tsconfig.node.json |
---|---|---|---|
角色 | 根配置(基础 / 共享) | 前端应用代码配置 | Node.js 环境代码配置 |
目标环境 | 通用基础配置 | 浏览器 | Node.js 运行时 |
继承关系 | 被其他配置继承 | 继承 tsconfig.json | 继承 tsconfig.json |
典型包含内容 | 全项目通用规则 | src/(业务代码) | 配置文件、工具脚本 |
特殊配置 | 无环境特定配置 | DOM 库、JSX 支持 | Node 类型、Node 模块系统 |