Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code 项目配置路径别名跳转 #66

Open
pfan123 opened this issue May 12, 2020 · 1 comment
Open

VS Code 项目配置路径别名跳转 #66

pfan123 opened this issue May 12, 2020 · 1 comment

Comments

@pfan123
Copy link
Owner

pfan123 commented May 12, 2020

在项目开发中我们会在 webpack 使用别名 alias 配置如:

    alias: {
      "@globalCss": path.join(__dirname, "/src/assets/style/common"),
      "@util": path.join(__dirname, "/src/utils"),
      "@assets": path.join(__dirname, "/src/assets"),
      "@": path.join(__dirname, "/src")
    }

方便我们引用不需要知道其详细路径,但会影响 VS Code 查找文件,使无法通过 Command 键 + 鼠标点击直接跳转到对应的文件:

VS Code对相对路径的引用有很友好的操作,如

import { moduleAccessRecord } from '../../../redux/actions/commonData'

import styles from "@/assets/style/BulletinManage/index.less";
import Footer from "@/components/footer";

发现 VS Code 提供 jsconfig.json 文件指定了根文件为 JavaScript 语言服务提供的功能的选项,通过如下配置就可以解决查找问题:

如果是 ts 路径查找,需要配置 tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/*"],
      "@util/*": ["src/utils/*"],
      "@assets/*": ["src/assets/*"]
    }
  },
  "exclude": ["node_modules", "dist"]
}

VS Code jsconfig.json

@MTTTM
Copy link

MTTTM commented Feb 11, 2022

不行,重启vscode还是不行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants