import path from 'node:path' import { fileURLToPath, URL } from 'node:url' import tailwindcss from '@tailwindcss/vite' import vue from '@vitejs/plugin-vue' import AutoImport from 'unplugin-auto-import/vite' import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' import Components from 'unplugin-vue-components/vite' import { defineConfig, loadEnv } from 'vite' // https://vite.dev/config/#using-environment-variables-in-config export default defineConfig(({ mode }) => { const cwd = fileURLToPath(new URL('./', import.meta.url)) const viteEnv = loadEnv(mode, cwd) as ImportMetaEnv return { resolve: { alias: { '@': path.resolve(cwd, 'src'), }, }, plugins: [ vue(), tailwindcss(), AutoImport({ imports: [ 'vue', 'vue-router', 'pinia', 'vue-i18n', { 'naive-ui': [ 'useDialog', 'useMessage', 'useNotification', 'useLoadingBar', ], }, ], }), Components({ dirs: [], resolvers: [ NaiveUiResolver(), ], }), ], server: { host: '0.0.0.0', port: 1002, open: false, proxy: { '/api': { target: viteEnv.VITE_APP_API_BASE_URL, changeOrigin: true, // 允许跨域 rewrite: path => path.replace('/api/', '/'), }, '/uploads': { target: viteEnv.VITE_APP_API_BASE_URL, changeOrigin: true, // 允许跨域 }, }, }, build: { reportCompressedSize: false, sourcemap: false, commonjsOptions: { ignoreTryCatch: false, }, }, } })