vite.config.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { defineConfig, loadEnv } from 'vite';
  2. import { createViteProxy, getRootPath, getSrcPath, setupVitePlugins, viteDefine } from './build';
  3. import { getServiceEnvConfig } from './.env-config';
  4. export default defineConfig(configEnv => {
  5. const viteEnv = loadEnv(configEnv.mode, process.cwd()) as unknown as ImportMetaEnv;
  6. const rootPath = getRootPath();
  7. const srcPath = getSrcPath();
  8. const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'Y';
  9. const envConfig = getServiceEnvConfig(viteEnv);
  10. return {
  11. base: viteEnv.VITE_BASE_URL,
  12. resolve: {
  13. alias: {
  14. '~': rootPath,
  15. '@': srcPath,
  16. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
  17. }
  18. },
  19. define: viteDefine,
  20. plugins: setupVitePlugins(viteEnv),
  21. css: {
  22. preprocessorOptions: {
  23. scss: {
  24. additionalData: `@use "./src/styles/scss/global.scss" as *;`
  25. }
  26. }
  27. },
  28. server: {
  29. host: '0.0.0.0',
  30. port: 3200,
  31. open: true,
  32. proxy: createViteProxy(isOpenProxy, envConfig)
  33. },
  34. optimizeDeps: {
  35. include: [
  36. '@antv/data-set',
  37. '@antv/g2',
  38. '@better-scroll/core',
  39. 'echarts',
  40. 'swiper',
  41. 'swiper/vue',
  42. 'vditor',
  43. 'wangeditor',
  44. 'xgplayer'
  45. ]
  46. },
  47. build: {
  48. reportCompressedSize: false,
  49. sourcemap: false,
  50. commonjsOptions: {
  51. ignoreTryCatch: false
  52. }
  53. }
  54. };
  55. });