vite.config.js 1.6 KB

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