tsconfig.json

Nuxt 会生成多个 TypeScript 配置文件,包含合理的默认值和你的别名。

Nuxt 自动生成 多个 TypeScript 配置文件(.nuxt/tsconfig.app.json.nuxt/tsconfig.server.json.nuxt/tsconfig.node.json.nuxt/tsconfig.shared.json),其中包含你在 Nuxt 项目中使用的已解析别名,以及其他合理的默认值。

你可以在项目根目录创建一个 tsconfig.json 来使用这些文件,内容如下:

tsconfig.json
{
  "files": [],
  "references": [
    {
      "path": "./.nuxt/tsconfig.app.json"
    },
    {
      "path": "./.nuxt/tsconfig.server.json"
    },
    {
      "path": "./.nuxt/tsconfig.shared.json"
    },
    {
      "path": "./.nuxt/tsconfig.node.json"
    }
  ]
}
根据需要,你可以自定义该文件的内容。但建议不要覆盖 targetmodulemoduleResolution
如果你需要自定义 paths,这会覆盖自动生成的路径别名。相反,我们建议你将需要的路径别名添加到 nuxt.config 中的 alias 属性,这样它们会被检测到并添加到自动生成的 tsconfig 中。