vite.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { defineConfig } from 'vite'
  2. import uni from '@dcloudio/vite-plugin-uni'
  3. import path from 'path'
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ command, mode }) => {
  6. const isApp = process.env.UNI_PLATFORM === 'app' || process.env.UNI_PLATFORM === 'app-harmony'
  7. return {
  8. plugins: [uni()],
  9. resolve: {
  10. alias: {
  11. '@': path.resolve(__dirname, './'),
  12. // 添加 uview-plus 别名
  13. 'uview-plus': path.resolve(__dirname, './node_modules/uview-plus')
  14. }
  15. },
  16. optimizeDeps: {
  17. include: ['uview-plus']
  18. },
  19. css: {
  20. preprocessorOptions: {
  21. scss: {
  22. // 可以在这里添加全局 scss 变量
  23. // 取消sass废弃API的报警
  24. silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],
  25. }
  26. }
  27. },
  28. server: {
  29. proxy: {
  30. // H5 开发环境代理配置
  31. '/base': {
  32. // target: 'http://localhost:8080',
  33. target:'https://nxy.gbdfarm.com:9000/pro-uniapp',
  34. changeOrigin: true,
  35. secure: false,
  36. rewrite: (path) => path.replace(/^\/base/, ''),
  37. },
  38. '/jessibuca': {
  39. target: 'https://nxy.gbdfarm.com:9000',
  40. changeOrigin: true
  41. },
  42. // WVP 视频平台代理配置
  43. '/wvp': {
  44. target: 'https://nxy.gbdfarm.com:9000',
  45. changeOrigin: true,
  46. secure: false,
  47. rewrite: (path) => path.replace(/^\/wvp/, '/wvp'),
  48. },
  49. // 腾讯地图API代理配置(解决CORS跨域问题)
  50. '/tencent-map-api': {
  51. target: 'https://apis.map.qq.com',
  52. changeOrigin: true,
  53. secure: false,
  54. rewrite: (path) => path.replace(/^\/tencent-map-api/, ''),
  55. },
  56. },
  57. },
  58. build: {
  59. // 生产环境移除 console
  60. minify: 'terser',
  61. terserOptions: {
  62. compress: {
  63. drop_console: true,
  64. drop_debugger: true
  65. }
  66. },
  67. // App 平台(包括鸿蒙)禁用代码分割,避免 iife 格式错误
  68. rollupOptions: isApp ? {
  69. output: {
  70. format: 'es',
  71. inlineDynamicImports: true, // 关键:禁用代码分割
  72. manualChunks: undefined
  73. }
  74. } : {
  75. output: {
  76. format: 'es',
  77. manualChunks: undefined
  78. }
  79. },
  80. target: 'esnext'
  81. }
  82. }})