vite.config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import vue from '@vitejs/plugin-vue';
  2. import { resolve } from 'path';
  3. import { defineConfig, loadEnv, ConfigEnv } from 'vite';
  4. import vueSetupExtend from 'vite-plugin-vue-setup-extend';
  5. import vueJsx from '@vitejs/plugin-vue-jsx'
  6. import { generateVersionFile } from "/@/utils/upgrade";
  7. const pathResolve = (dir: string) => {
  8. return resolve(__dirname, '.', dir);
  9. };
  10. const alias: Record<string, string> = {
  11. '/@': pathResolve('./src/'),
  12. '@views': pathResolve('./src/views'),
  13. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  14. '@dvaformflow':pathResolve('./src/viwes/plugins/dvaadmin_form_flow/src/')
  15. };
  16. const viteConfig = defineConfig((mode: ConfigEnv) => {
  17. const env = loadEnv(mode.mode, process.cwd());
  18. // 当Vite构建时,生成版本文件
  19. generateVersionFile()
  20. return {
  21. plugins: [vue(), vueJsx(), vueSetupExtend()],
  22. root: process.cwd(),
  23. resolve: { alias },
  24. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  25. optimizeDeps: {
  26. include: ['element-plus/es/locale/lang/zh-cn', 'element-plus/es/locale/lang/en', 'element-plus/es/locale/lang/zh-tw'],
  27. },
  28. server: {
  29. host: '0.0.0.0',
  30. port: env.VITE_PORT as unknown as number,
  31. open: false,
  32. hmr: true,
  33. proxy: {
  34. '/gitee': {
  35. target: 'https://gitee.com',
  36. ws: true,
  37. changeOrigin: true,
  38. rewrite: (path) => path.replace(/^\/gitee/, ''),
  39. },
  40. },
  41. },
  42. build: {
  43. outDir: env.VITE_DIST_PATH || 'dist',
  44. chunkSizeWarningLimit: 1500,
  45. rollupOptions: {
  46. output: {
  47. entryFileNames: `assets/[name].[hash].js`,
  48. chunkFileNames: `assets/[name].[hash].js`,
  49. assetFileNames: `assets/[name].[hash].[ext]`,
  50. compact: true,
  51. manualChunks: {
  52. vue: ['vue', 'vue-router', 'pinia'],
  53. echarts: ['echarts'],
  54. },
  55. },
  56. },
  57. },
  58. css: { preprocessorOptions: { css: { charset: false } } },
  59. define: {
  60. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  61. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  62. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  63. __VERSION__: JSON.stringify(process.env.npm_package_version),
  64. },
  65. };
  66. });
  67. export default viteConfig;