skip to Main Content

Using a Vite app I can include this in my vite.config.js:

resolve: {
    alias: {
        "@": path.resolve(__dirname, "./src"),
    },
},

which allows me to use the ‘@’ symbol (at character) for path names. This lets me have imports that look like this:

import Home from "@/pages/Home.vue";

As opposed to this:

import Home from "../../../pages/Home.vue";

The problem is that intellisense won’t show up in any meaningful way when using the ‘@’ path but it will when I use the ‘..’ path. How do I enable path intellisense starting with ‘@’

Pictures to clarify what I mean by "intellisense won’t show up in any meaningful way when using the ‘@’ path":
Using ‘..’ path

Using ‘@’ path

2

Answers


  1. You also need to tell vscode with jsconfig.json or tsconfig.json file, for example:

    {
      "compilerOptions": {
        "baseUrl": ".",
        "target": "es6",
        "paths": {
          "@/*": ["./src/*"],
        }
      }
    }
    
    Login or Signup to reply.
  2. You must add jsconfig.json file in root your project with paths parameter value:

    "paths": {
      "@/*": [
        "./src/*"
      ]
    },
    

    jsconfig.json

    structure of project

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search