vscode 配置@根路径

一、安装依赖

npm install path --save

二、安装插件Path Intellisense

三、设置-搜索path-intellisense-在settings.json中编辑

 配置:

{
  "path-intellisense.mappings": {
    "@": "${workspaceRoot}/src"
  },
}

四、vite.config.js中的别名配置。确保 @ 符号已正确映射到 src 目录

import { defineConfig } from 'vite';
import path from 'path';

export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  // 其他配置...
});

五、在项目根目录下,创建jsconfig.json文件,内容如下:

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "paths": {
      "@/*": [
        "src/*"
      ]
    }
  },
  "exclude": [
    "node_modules"
  ]
}

猜你喜欢

转载自blog.csdn.net/weixin_44523517/article/details/130260573
今日推荐