# VS Code 配置自动补全路径别名 @

# Path Intellisense

  • 安装 Path Intellisense 插件

  • 配置 VS Code 的配置文件 settings.json 加入:

      "path-intellisense.mappings": {
        "@": "${workspaceRoot}/src",
        "~@": "${workspaceRoot}/src",
      },
    
    1
    2
    3
    4
  • 项目根目录创建 jsconfig.json 并写入:

        {
          "compilerOptions": {
            "target": "es5",
            "baseUrl": "./",
            "paths": {
              "@/*": ["src/*"],
            }
          },
          "exclude": ["node_modules"]
        }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

# Path Autocomplete 插件

配置 VS Code settings.json

    "path-autocomplete.pathMappings": {
        "@": "${folder}/src",
        "~@": "${folder}/src",
    },
1
2
3
4

jsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/*"],
    }
  },
  "exclude": ["node_modules"]
}
1
2
3
4
5
6
7
8
9
10