vite.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. css: {
  17. preprocessorOptions: {
  18. scss: {
  19. // 可以在这里添加全局 scss 变量
  20. // 取消sass废弃API的报警
  21. silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],
  22. }
  23. }
  24. },
  25. server: {
  26. proxy: {
  27. // H5 开发环境代理配置
  28. '/base': {
  29. // target: 'http://localhost:8080',
  30. target:'https://azn.gbdfarm.com/prod-api',
  31. changeOrigin: true,
  32. secure: false,
  33. rewrite: (path) => path.replace(/^\/base/, ''),
  34. },
  35. // WVP 视频平台代理配置
  36. '/wvp': {
  37. target: 'https://nxy.gbdfarm.com:9000',
  38. changeOrigin: true,
  39. secure: false,
  40. rewrite: (path) => path.replace(/^\/wvp/, '/wvp'),
  41. },
  42. },
  43. },
  44. build: {
  45. // 生产环境移除 console
  46. minify: 'terser',
  47. terserOptions: {
  48. compress: {
  49. drop_console: true,
  50. drop_debugger: true
  51. }
  52. },
  53. // App 平台(包括鸿蒙)禁用代码分割,避免 iife 格式错误
  54. rollupOptions: isApp ? {
  55. output: {
  56. format: 'es',
  57. inlineDynamicImports: true, // 关键:禁用代码分割
  58. manualChunks: undefined
  59. }
  60. } : {
  61. output: {
  62. format: 'es',
  63. manualChunks: undefined
  64. }
  65. },
  66. target: 'esnext'
  67. }
  68. }})