vite5+ts设置别名

237 阅读1分钟

vite5+ts+react设置别名

Snipaste_2024-08-27_09-09-51.png

```import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  //加入下面内容👇
  resolve: {
    alias: {
      // '@' 将指向 'src' 目录
      '@': path.resolve(__dirname, 'src'),//安装 pnpm install @types/node -D
      // 'components' 将指向 'src/components' 目录
      components: path.resolve(__dirname, 'src/components'),
    },
  },
  //👆
});
//↑ vite.config.ts

`json`
//tsconfig.app.json
 "compilerOptions": {
   
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  },
over