vite.config.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import path from 'path';
  2. import type { PluginOption } from 'vite';
  3. import { defineConfig, loadEnv } from 'vite';
  4. import vue from '@vitejs/plugin-vue';
  5. import { VitePWA } from 'vite-plugin-pwa';
  6. function setupPlugins(env: ImportMetaEnv): PluginOption[] {
  7. return [
  8. vue(),
  9. env.VITE_GLOB_APP_PWA === 'true' &&
  10. VitePWA({
  11. injectRegister: 'auto',
  12. manifest: {
  13. name: 'chatGPT',
  14. short_name: 'chatGPT',
  15. icons: [
  16. { src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
  17. { src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
  18. ],
  19. },
  20. }),
  21. ];
  22. }
  23. export default defineConfig((env) => {
  24. const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv;
  25. return {
  26. resolve: {
  27. alias: {
  28. '@': path.resolve(process.cwd(), 'src'),
  29. },
  30. },
  31. plugins: setupPlugins(viteEnv),
  32. server: {
  33. host: '0.0.0.0',
  34. port: 1002,
  35. open: false,
  36. proxy: {
  37. '/api': {
  38. target: viteEnv.VITE_APP_API_BASE_URL,
  39. changeOrigin: true, // 允许跨域
  40. rewrite: (path) => path.replace('/api/', '/'),
  41. },
  42. },
  43. },
  44. build: {
  45. reportCompressedSize: false,
  46. sourcemap: false,
  47. commonjsOptions: {
  48. ignoreTryCatch: false,
  49. },
  50. },
  51. };
  52. });