vite.config.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. ],
  40. resolve: {
  41. alias: {
  42. '@': fileURLToPath(new URL('./src', import.meta.url)),
  43. '@request': fileURLToPath(new URL('./request', import.meta.url)),
  44. '@model': fileURLToPath(new URL('./model', import.meta.url)),
  45. '@tool': fileURLToPath(new URL('./tool', import.meta.url)),
  46. },
  47. },
  48. server: {
  49. host: '0.0.0.0',
  50. port: 51001,
  51. proxy: {
  52. '/manager': {
  53. target: env.APP_API_PROXY,
  54. secure: false,
  55. changeOrigin: false,
  56. logLevel: 'debug',
  57. },
  58. },
  59. },
  60. };
  61. });