TypeScript配置-- 2. 了解ts配置项,根据vite项目了解typescript配置文件,tsconfig.json、tsconfig.node.json、
warning:
这篇文章距离上次修改已过441天,其中的内容可能已经有所变动。
在Vite项目中,tsconfig.json 文件用于配置 TypeScript 编译器的行为。以下是一些常见的配置项:
compilerOptions: 编译选项,包括目标ES版本、模块系统、是否生成源映射文件等。include: 指定哪些文件或文件夹应该被包含进行编译。exclude: 指定哪些文件或文件夹应该被排除在编译之外。extends: 可以继承其他配置文件。
下面是一个简单的 tsconfig.json 示例:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
},
"lib": ["esnext", "dom", "dom.iterable"]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"exclude": [
"node_modules"
]
}在这个配置中,compilerOptions 指定了编译目标为 esnext,模块系统使用 esnext,启用了严格模式 (strict),保留JSX。include 指定了需要编译的文件类型,exclude 排除了 node_modules 目录。这样配置后,Vite 会使用 TypeScript 来处理 src 目录下的 TypeScript、TypeScript React、Vue 文件。
评论已关闭