Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup PhpStorm / WebStorm to work with Vite aliases?

Vite isn't supported by the PhpStorm / WebStorm yet, so given following Vite configuration:

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, '/src'),
    },
  },
});

it doesn't recognize the following import correctly:

import { getAllItems } from '@/api'

How can this be setup to work correctly?

like image 554
entio Avatar asked Sep 12 '25 00:09

entio


1 Answers

Create a JavaScript file in a root of your project (name doesn't really matter, I'll go with phpstorm.config.js) and mirror your aliases configuration like shown below:

System.config({
  "paths": {
    "@/*": "./src/*",
  }
});

Php/Webstorm will pick it up automagically. It's probably a good idea to add it to the .gitignore.


Another option is to create a jsconfig.json following the pattern below:

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

Read more on this solution in the docs of VSCode

like image 199
entio Avatar answered Sep 14 '25 20:09

entio