vite.config.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import vue from '@vitejs/plugin-vue';
  2. import { resolve } from 'path';
  3. import { ConfigEnv, defineConfig, loadEnv } from 'vite';
  4. import vueJsx from '@vitejs/plugin-vue-jsx';
  5. const pathResolve = (dir: string) => {
  6. return resolve(__dirname, '.', dir);
  7. };
  8. const alias: Record<string, string> = {
  9. '/@': pathResolve('./src/'),
  10. '@views': pathResolve('./src/views'),
  11. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  12. '@dvaformflow': pathResolve('./src/viwes/plugins/dvaadmin_form_flow/src/')
  13. };
  14. const viteConfig = defineConfig((mode: ConfigEnv) => {
  15. const env = loadEnv(mode.mode, process.cwd());
  16. return {
  17. plugins: [
  18. vue(),
  19. vueJsx()
  20. // vueSetupExtend()
  21. ],
  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: true,
  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;