002 vue3-admin项目的目录及文件说明之tsconfig.json文件
说明
tsconfig.json 是 TypeScript 项目的核心配置文件,用于指定 TypeScript 编译器的编译选项和项目设置。
基本结构
{
"compilerOptions": {
/* 编译选项 */
},
"include": [
/* 包含文件 */
],
"exclude": [
/* 排除文件 */
],
"extends": "/* 继承配置 */",
"files": [
/* 指定文件 */
],
"references": [
/* 项目引用 */
]
}
核心配置项
1 compilerOptions 属性
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "preserve"
}
严格模式配置:
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"alwaysStrict": true
}
模块解析配置
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"rootDirs": ["src", "tests"],
"typeRoots": ["node_modules/@types", "src/types"],
"types": ["node", "jest"]
}
输出配置:
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"declarationDir": "./dist/types",
"sourceMap": true,
"inlineSourceMap": false,
"outFile": "./dist/bundle.js"
}
检查与报告配置
"compilerOptions": {
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
}
2 include 属性
"include": [ "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts" ]
3 exclude 属性
"exclude": [ "node_modules", "dist", "build", "**/*.spec.ts", "**/*.test.ts" ]
4 extends 属性
"extends": "@vue/tsconfig/tsconfig.dom.json"
5 files 属性
"files": [ "src/main.ts", "src/polyfills.ts" ]
6 references 属性
"references": [
{ "path": "./tsconfig.node.json" },
{ "path": "./tsconfig.app.json" }
]
与tsconfig.app.json、tsconfig.node.json文件关系
{
"files": [],
"references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }]
}
1 files 属性
2 references 属性
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
项目引用(Project References)机制
什么是项目引用?
工作原理
项目结构推测
优势分析
1 性能优化
2 代码组织
3 开发体验
常见应用场景
1 前端框架项目
2 全栈应用
3 库开发
总结

浙公网安备 33010602011771号