跳至主要內容
vite 别名配置注意事项

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/, ''),
      },
    },
  },
});

h7mlvitevite小于 1 分钟