vite.config.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Copyright (c) 2013-Now https://jeesite.com All rights reserved.
  3. * No deletion without permission, or be held responsible to law.
  4. * @author ThinkGem
  5. */
  6. import type { UserConfig, ConfigEnv } from 'vite';
  7. import { defineConfig, loadEnv } from 'vite';
  8. import path from 'path';
  9. import {
  10. createBuildOptions,
  11. createCSSOptions,
  12. createDefineOptions,
  13. createEsBuildOptions,
  14. createServerOptions,
  15. createVitePlugins,
  16. wrapperEnv,
  17. } from '@jeesite/vite';
  18. export default defineConfig(async ({ command, mode }: ConfigEnv) => {
  19. const root = process.cwd();
  20. const isBuild = command === 'build';
  21. const viteEnv = wrapperEnv(loadEnv(mode, root));
  22. const config: UserConfig = {
  23. root,
  24. base: viteEnv.VITE_PUBLIC_PATH,
  25. define: await createDefineOptions(),
  26. plugins: createVitePlugins(isBuild, viteEnv),
  27. server: createServerOptions(viteEnv),
  28. esbuild: createEsBuildOptions(viteEnv),
  29. build: createBuildOptions(viteEnv),
  30. css: createCSSOptions(),
  31. resolve: {
  32. alias: {
  33. '@jeesite/web': path.resolve(__dirname, './'),
  34. },
  35. },
  36. };
  37. return config;
  38. });