tsconfig.json

了解 Nuxt 如何管理项目中不同部分的 TypeScript 配置。

Nuxt 会自动生成一个 .nuxt/tsconfig.json 文件,其中包含你在 Nuxt 项目中使用的已解析别名,以及其他合理的默认配置。

你的 Nuxt 项目应在根目录包含以下 tsconfig.json 文件:

tsconfig.json
{
  "extends": "./.nuxt/tsconfig.json"
}
根据需要,你可以自定义此文件的内容。但建议不要覆盖 targetmodulemoduleResolution
如果你需要自定义 paths,这将覆盖自动生成的路径别名。相反,我们建议你将需要的路径别名添加到 nuxt.config 文件中的 alias 属性里,这样它们会被自动拾取并添加到自动生成的 tsconfig 中。

扩展 TypeScript 配置

你可以在 nuxt.config.ts 文件中,为 Nuxt 项目的各个环境(appserver)自定义 TypeScript 配置。

nuxt.config.ts
// @errors: 2353
export default defineNuxtConfig({
  typescript: {
    // 自定义 tsconfig.app.json
    tsConfig: {
      // ...
    },
  },
  nitro: {
    typescript: {
      // 自定义 tsconfig.server.json
      tsConfig: {
        // ...
      },
    },
  },
})