vite.config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. },
  36. },
  37. build: {
  38. // 生产环境移除 console
  39. minify: 'terser',
  40. terserOptions: {
  41. compress: {
  42. drop_console: true,
  43. drop_debugger: true
  44. }
  45. },
  46. // App 平台(包括鸿蒙)禁用代码分割,避免 iife 格式错误
  47. rollupOptions: isApp ? {
  48. output: {
  49. format: 'es',
  50. inlineDynamicImports: true, // 关键:禁用代码分割
  51. manualChunks: undefined
  52. }
  53. } : {
  54. output: {
  55. format: 'es',
  56. manualChunks: undefined
  57. }
  58. },
  59. target: 'esnext'
  60. }
  61. }})