vite.config.js 1.9 KB

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