Skip to content

tsconfig.json 文件

自定义配置别名

config index.js 添加别名配置

json
# 官方例子
alias: {
  "@/": path.resolve(__dirname, "..", "src/"),
  "@/components": path.resolve(__dirname, "..", "src/components"),
  "@/services": path.resolve(__dirname, "..", "src/services"),
  "@/utils": path.resolve(__dirname, "..", "src/utils")
},

需要在项目根目录下的 jsconfig.json 或者 tsconfig.json 中配置 paths 让编辑器认得我们的别名,形式如下:

json
# 官方例子
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/components/*": ["./src/components/*"],
      "@/utils/*": ["./src/utils/*"],
      "@/package": ["./package.json"],
      "@/project": ["./project.config.json"]
    }
  }
}