vite.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // WVP 视频平台代理配置
  39. '/wvp': {
  40. target: 'https://nxy.gbdfarm.com:9000',
  41. changeOrigin: true,
  42. secure: false,
  43. rewrite: (path) => path.replace(/^\/wvp/, '/wvp'),
  44. },
  45. // 腾讯地图API代理配置(解决CORS跨域问题)
  46. '/tencent-map-api': {
  47. target: 'https://apis.map.qq.com',
  48. changeOrigin: true,
  49. secure: false,
  50. rewrite: (path) => path.replace(/^\/tencent-map-api/, ''),
  51. },
  52. },
  53. },
  54. build: {
  55. // 生产环境移除 console
  56. minify: 'terser',
  57. terserOptions: {
  58. compress: {
  59. drop_console: true,
  60. drop_debugger: true
  61. }
  62. },
  63. // App 平台(包括鸿蒙)禁用代码分割,避免 iife 格式错误
  64. rollupOptions: isApp ? {
  65. output: {
  66. format: 'es',
  67. inlineDynamicImports: true, // 关键:禁用代码分割
  68. manualChunks: undefined
  69. }
  70. } : {
  71. output: {
  72. format: 'es',
  73. manualChunks: undefined
  74. }
  75. },
  76. target: 'esnext'
  77. }
  78. }})