VS Code、React 项目、使用绝对导入路径时的智能感知

时间:2021-05-26 09:51:54

标签: reactjs visual-studio-code components intellisense absolute-path

在我的反应项目中使用时:

//package.json
"name": "app"

那么智能感知不适用于绝对路径导入

//SomeComponent.js
import {StorageKeys} from 'app/Constants' // inellisense dont work
import {StorageKeys} from '../../Constants' // intellisense works

尝试了一些关于“jsconfig.json”和设置编译器的基本 url 的建议,但没有成功。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

好的,再次进行 RTFM 和 RTFM。

{
  "compilerOptions": {
      "target": "ES6",
      "baseUrl": "./",
      "paths" : {
        "app/*" : ["./*"]
      }
  },
  "exclude": [
      "node_modules",
      "**/node_modules/*"
  ]
}