vscode 引入“@xx/xx”此类文件无法点击跳转?

692 阅读1分钟

vscode 引入“@xx/xx”此类文件无法点击跳转?

用过webstorm的同学都知道webstorm引入上述路径时,点击可直接跳转。但是作为vscode用户怎么才能实现上述这么方便实用的功能呢?

首先在项目根目录下新建文件jsconfig.json

在jsconfig.json文件里新增如下代码:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@global/*": ["src/global/*"], //相当于适配路径:"@global/views/index"
      "@committee/*": ["src/huayang-committee/*"],
      "@distribute/*": ["src/huayang-distribute/*"],
      "@member/*": ["src/huayang-member/*"]
    },
    "target": "ES6",
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

完成上面的配置后重启vscode即可点击跳转;

上述往往这个是个人配置,团队协作时此文件(jsconfig.json)加得加入gitignore哦~