简体   繁体   中英

How can I make VSCode auto complete paths (parses) if I use '@ => ./src/component' in Vite project

In a Vite project my config file is as follow

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

export default defineConfig({
  plugins: [vue()],

  build: {
    outDir: 'public',
  },

  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src/components'),
      '~': path.resolve(__dirname, './src'),
    },
  },

  envDir: './',
  envPrefix: 'STO_',
});

VSCode doesn't parse paths starting with @ or ~ so if a file doesn't exists I don't even see the error, and I have bad auto-completion experience.

In PhpStorm I think there is a file called phpstorm.config.js where we can tell the editor how to parse such characters.

System.config({
  paths: {
    '@/*': './src/components/*',
    '~/*': './src/*',
  },
});

How can I fix this in VSCode? Is there a similar approach?

same approach as with a webpack

i configured my tsconfig.json (or alternatively jsconfig.json ) to re-map the import statements:

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

same answer as https://stackoverflow.com/a/39414291/13278193

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM