vite TypeScript配置文件
时间: 2023-08-11 15:06:51 浏览: 61
在使用 Vite 时,您可以通过在项目根目录中创建一个 `tsconfig.json` 文件来配置 TypeScript。以下是一个基本的配置示例:
```json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"lib": ["esnext", "dom"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "tests/**/*.ts", "tests/**/*.tsx"],
"exclude": ["node_modules", "dist"]
}
```
这个配置文件:
- 将编译目标设置为 ESNext。
- 将模块设置为 ESNext。
- 启用了严格模式。
- 保留了 JSX 以供后续编译。
- 启用了 sourceMap。
- 启用了 esModuleInterop。
- 允许合成默认导入。
- 配置了模块解析和 JSON 模块。
- 指定了 TypeScript 需要使用的库。
您可以根据需要进行更改或添加其他选项。此外,根据您的项目结构,您可能需要更改 `include` 和 `exclude` 选项以确保 TypeScript 编译器可以正确地找到和编译您的文件。
希望这可以帮助您开始使用 TypeScript 和 Vite。