Nuxt 自动生成 多个 TypeScript 配置文件(.nuxt/tsconfig.app.json、.nuxt/tsconfig.server.json、.nuxt/tsconfig.node.json 和 .nuxt/tsconfig.shared.json),其中包含项目推荐的基本 TypeScript 配置,引用了自动导入、API 路由类型、路径别名等。
您的 Nuxt 项目根目录应包含以下 tsconfig.json 文件:
{
"files": [],
"references": [
{
"path": "./.nuxt/tsconfig.app.json"
},
{
"path": "./.nuxt/tsconfig.server.json"
},
{
"path": "./.nuxt/tsconfig.shared.json"
},
{
"path": "./.nuxt/tsconfig.node.json"
}
]
}
nuxt.config.ts 文件进行扩展。您可以在 nuxt.config.ts 文件中为每个上下文(app、shared、node 和 server)自定义 Nuxt 项目的 TypeScript 配置。
export default defineNuxtConfig({
typescript: {
// 自定义 tsconfig.app.json
tsConfig: {
// ...
},
// 自定义 tsconfig.shared.json
sharedTsConfig: {
// ...
},
// 自定义 tsconfig.node.json
nodeTsConfig: {
// ...
},
},
nitro: {
typescript: {
// 自定义 tsconfig.server.json
tsConfig: {
// ...
},
},
},
})