vite.config.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import path from 'path';
  4. import vueI18n from '@intlify/vite-plugin-vue-i18n';
  5. import dotenv from 'dotenv';
  6. // 加载环境变量
  7. dotenv.config();
  8. interface ImportMetaEnv {
  9. readonly VITE_API_URL: string; // 示例环境变量
  10. }
  11. interface ImportMeta {
  12. readonly env: ImportMetaEnv;
  13. }
  14. export default defineConfig({
  15. plugins: [
  16. vue(),
  17. vueI18n({
  18. include: path.resolve(__dirname, './src/locales/**'),
  19. }),
  20. ],
  21. resolve: {
  22. alias: {
  23. '@': path.resolve(__dirname, './src'),
  24. },
  25. },
  26. optimizeDeps: {
  27. include: ['quill'],
  28. },
  29. define: {
  30. __API_URL__: JSON.stringify(process.env.VITE_API_URL),
  31. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false'
  32. },
  33. // 配置前端服务地址和端口
  34. server: {
  35. host: '0.0.0.0',
  36. port: 5173,
  37. https: false,
  38. proxy: {
  39. '/api': {
  40. target: 'http://192.168.1.141:18082',
  41. changeOrigin: true,
  42. rewrite: (path) => path.replace(/^\/api/, ''),
  43. },
  44. },
  45. },
  46. });