vite.config.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import process from 'node:process';
  2. import { URL, fileURLToPath } from 'node:url';
  3. import { defineConfig, loadEnv } from 'vite';
  4. import { setupVitePlugins } from './build/plugins';
  5. import { createViteProxy, getBuildTime } from './build/config';
  6. export default defineConfig(configEnv => {
  7. const viteEnv = loadEnv(configEnv.mode, process.cwd()) as unknown as Env.ImportMeta;
  8. const buildTime = getBuildTime();
  9. return {
  10. base: viteEnv.VITE_BASE_URL,
  11. resolve: {
  12. alias: {
  13. '~': fileURLToPath(new URL('./', import.meta.url)),
  14. '@': fileURLToPath(new URL('./src', import.meta.url))
  15. }
  16. },
  17. css: {
  18. preprocessorOptions: {
  19. scss: {
  20. additionalData: `@use "./src/styles/scss/global.scss" as *;`
  21. }
  22. }
  23. },
  24. plugins: setupVitePlugins(viteEnv, buildTime),
  25. define: {
  26. BUILD_TIME: JSON.stringify(buildTime)
  27. },
  28. server: {
  29. host: '0.0.0.0',
  30. port: 9527,
  31. open: true,
  32. proxy: createViteProxy(viteEnv, configEnv.command === 'serve'),
  33. fs: {
  34. cachedChecks: false
  35. }
  36. },
  37. preview: {
  38. port: 9725
  39. },
  40. build: {
  41. reportCompressedSize: false,
  42. sourcemap: viteEnv.VITE_SOURCE_MAP === 'Y',
  43. commonjsOptions: {
  44. ignoreTryCatch: false
  45. }
  46. }
  47. };
  48. });