|
|
import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' import { viteMockServe } from 'vite-plugin-mock'
import jotaiDebugLabel from 'jotai/babel/plugin-debug-label' import jotaiReactRefresh from 'jotai/babel/plugin-react-refresh'
//import { TanStackRouterVite } from '@tanstack/router-vite-plugin'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// 根据当前工作目录中的 `mode` 加载 .env 文件
// 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
// @ts-ignore fix process
const env = loadEnv(mode, process.cwd(), '') return { //定义别名的路径
resolve: { alias: { '@': '/src', }, }, server: { cors: { origin: '*' }, proxy: { '/api/v1/package': { target: 'http://154.88.7.8:45321', changeOrigin: true, rewrite: (path) => { //replace /api/v1/package to /package/v1
//http://154.88.7.8:45321/package/v1/list
path = path.replace('/api/v1/package', '/package/v1') console.log(path) return path } }, '/api/v1/movie': { target: 'http://47.113.117.106:10000', changeOrigin: true, rewrite: (path) => { return path } }, '/api': { target: env.API_URL, changeOrigin: true, rewrite: (path) => { return path } } }, }, plugins: [ react({ babel: { presets: [ 'jotai/babel/preset' ], plugins: [ jotaiDebugLabel, jotaiReactRefresh ] }, }), viteMockServe({ // 是否启用 mock 功能(默认值:process.env.NODE_ENV !== 'production')
enable: false,
// mock 文件的根路径,默认值:'mocks'
mockPath: 'mock', logger: true, }), //TanStackRouterVite(),
], } })
|