Modify the vite. Config. Js

At the same level as plugins, add

resolve: {
    alias: {
      '@': path.resolve(__dirname, '/src'),
    },
  }
Copy the code

Resolve ts path alias identification problem

In the case of ts projects, simply adding above is not enough because the editor does not automatically recognize alias paths, such as:

Modify tsconfig.json to compilerOptions

"baseUrl": ".",
    "paths": {
      "@/*": [
        "src/*"
      ]
  }
Copy the code

After the change, you’d better restart the project to take effect