vite 别名配置注意事项

h7mlvitevite小于 1 分钟

vite 别名配置注意事项

  1. Vite config
image-20220411165325332
image-20220411165325332
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import * as path from 'path';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  server: {
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://xuanyuan.jinuo.fun:8080/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
});
  1. Tsconfig.json

image-20220411165514379

告诉 TS 解析如何解析某些路径

注意./src/* 后边这个*一定要加