vite.config.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { fileURLToPath, URL } from 'node:url';
  2. import { defineConfig, loadEnv } from 'vite';
  3. import vue from '@vitejs/plugin-vue';
  4. import vueJsx from '@vitejs/plugin-vue-jsx';
  5. import vueDevTools from 'vite-plugin-vue-devtools';
  6. import legacy from '@vitejs/plugin-legacy';
  7. import AutoImport from 'unplugin-auto-import/vite';
  8. import Components from 'unplugin-vue-components/vite';
  9. import { VantResolver } from '@vant/auto-import-resolver';
  10. import tailwindcss from '@tailwindcss/vite';
  11. // https://vite.dev/config/
  12. export default defineConfig(({ mode, command }) => {
  13. const dir = './.env';
  14. const env = loadEnv(mode, dir, '');
  15. const prefix = env.APP_ENV_PREFIX || 'VITE_';
  16. return {
  17. envDir: dir,
  18. envPrefix: prefix,
  19. define: {
  20. __app_base__: JSON.stringify(env.APP_BASE),
  21. __app_name__: JSON.stringify(process.env.npm_package_name),
  22. __app_version__: JSON.stringify(process.env.npm_package_version),
  23. },
  24. base: env.APP_BASE,
  25. plugins: [
  26. vue(),
  27. vueJsx(),
  28. vueDevTools(),
  29. tailwindcss(),
  30. AutoImport({
  31. imports: ['vue', 'vue-router', 'pinia'],
  32. resolvers: [VantResolver()],
  33. dts: '@types/auto-imports.d.ts',
  34. }),
  35. Components({
  36. resolvers: [VantResolver()],
  37. dts: '@types/components.d.ts',
  38. }),
  39. legacy({
  40. targets: ['chrome >=49'],
  41. modernTargets: ['chrome >=61'],
  42. polyfills: true,
  43. modernPolyfills: true,
  44. }),
  45. ],
  46. resolve: {
  47. alias: {
  48. '@': fileURLToPath(new URL('./src', import.meta.url)),
  49. '@request': fileURLToPath(new URL('./request', import.meta.url)),
  50. '@model': fileURLToPath(new URL('./model', import.meta.url)),
  51. '@tool': fileURLToPath(new URL('./tool', import.meta.url)),
  52. },
  53. },
  54. server: {
  55. host: '0.0.0.0',
  56. port: 51001,
  57. proxy: {
  58. '/manager': {
  59. target: env.APP_API_PROXY,
  60. secure: false,
  61. changeOrigin: false,
  62. logLevel: 'debug',
  63. },
  64. },
  65. },
  66. };
  67. });