[英]Why does Vite create two TypeScript config files: tsconfig.json and tsconfig.node.json?
I'm using Vite to create a new React + TypeScript project .我正在使用 Vite 创建 一个新的 React + TypeScript 项目。
After creating the project, there are two TypeScript config files on the root folder: tsconfig.json
and tsconfig.node.json
.创建项目后,根文件夹中有两个 TypeScript 配置文件:
tsconfig.json
和tsconfig.node.json
。 These are the contents of each one:这些是每一个的内容:
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
},
"include": ["vite.config.ts"]
}
Why do we need two?为什么我们需要两个?
What does the second one do?第二个是做什么的?
Can I remove the second one?我可以删除第二个吗?
You need two different TS configs because the project is using two different environments in which the TypeScript code is executed:您需要两个不同的 TS 配置,因为该项目使用两个不同的执行 TypeScript 代码的环境:
src
folder) is targeting (will be running) inside the browsersrc
文件夹)在浏览器内定位(将运行)So there are two different configs for those two environments and two distinct sets of source files...所以这两个环境有两种不同的配置和两组不同的源文件......
And no, you probably don't want to delete the tsconfig.node.json
but you can probably rename it to something like tsconfig.vite.json
to make it's purpose more clear不,您可能不想删除
tsconfig.node.json
但您可能可以将其重命名为tsconfig.vite.json
以使其目的更明确
As mentioned by Michal Levý, these are different configs for different environments.正如 Michal Levý 所提到的,这些是针对不同环境的不同配置。
You will notice that tsconfig.json
includes a "references" key which points to an array that includes the tsconfig.node.json
file.您会注意到
tsconfig.json
包含一个“references”键,它指向一个包含tsconfig.node.json
文件的数组。 If you wish to change the filename of your vite tsconfig, be sure to update this reference.如果您希望更改 vite tsconfig 的文件名,请务必更新此参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.