vite.config.ts 1.3 KB

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