vite.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { defineConfig } from 'vite';
  2. import uni from '@dcloudio/vite-plugin-uni';
  3. import { nodePolyfills } from 'vite-plugin-node-polyfills';
  4. // https://vitejs.dev/config/
  5. export default defineConfig({
  6. plugins: [
  7. uni(),
  8. nodePolyfills({
  9. // 启用需要的 polyfills
  10. include: ['buffer', 'crypto', 'stream', 'util'],
  11. globals: {
  12. Buffer: true,
  13. global: true,
  14. process: true,
  15. },
  16. }),
  17. ],
  18. define: {
  19. global: 'globalThis',
  20. },
  21. css: {
  22. preprocessorOptions: {
  23. scss: {
  24. // 静默废弃警告,特别是来自第三方依赖的警告
  25. silenceDeprecations: ['legacy-js-api', 'import'],
  26. // 静默来自 node_modules 的警告
  27. quietDeps: true,
  28. charset: false,
  29. },
  30. },
  31. },
  32. // 开发服务器配置
  33. server: {
  34. port: 5173,
  35. host: '0.0.0.0',
  36. open: true,
  37. // 代理配置解决CORS问题
  38. proxy: {
  39. '/api': {
  40. target: 'http://localhost:8080',
  41. changeOrigin: true,
  42. rewrite: (path) => path.replace(/^\/api/, ''),
  43. },
  44. },
  45. },
  46. });