Nuxt 会自动生成一个 .nuxt/tsconfig.json 文件,其中包含你在 Nuxt 项目中使用的已解析别名,以及其他合理的默认配置。
你可以通过在项目根目录创建一个内容如下的 tsconfig.json 文件来利用这一点:
{
"extends": "./.nuxt/tsconfig.json"
}
target、module 和 moduleResolution。paths,这将覆盖自动生成的路径别名。相反,我们建议你将需要的路径别名添加到 nuxt.config 文件中的 alias 属性里,这样它们会被自动拾取并添加到自动生成的 tsconfig 中。你可以在 nuxt.config.ts 文件中,为 Nuxt 项目的各个环境(app 和 server)自定义 TypeScript 配置。
export default defineNuxtConfig({
typescript: {
// 自定义 tsconfig.app.json
tsConfig: {
// ...
},
},
nitro: {
typescript: {
// 自定义 tsconfig.server.json
tsConfig: {
// ...
},
},
},
})