vite.config.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import vue from '@vitejs/plugin-vue';
  2. import { resolve } from 'path';
  3. import { defineConfig, loadEnv, ConfigEnv } from 'vite';
  4. const pathResolve = (dir: string): any => {
  5. return resolve(__dirname, '.', dir);
  6. };
  7. const alias: Record<string, string> = {
  8. '/@': pathResolve('./src/'),
  9. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  10. };
  11. const viteConfig = defineConfig((mode: ConfigEnv) => {
  12. const env = loadEnv(mode.mode, process.cwd());
  13. return {
  14. plugins: [vue()],
  15. root: process.cwd(),
  16. resolve: { alias },
  17. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  18. hmr: true,
  19. optimizeDeps: {
  20. include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw'],
  21. },
  22. server: {
  23. host: '0.0.0.0',
  24. port: env.VITE_PORT as unknown as number,
  25. open: env.VITE_OPEN,
  26. proxy: {
  27. '/gitee': {
  28. target: 'https://gitee.com',
  29. ws: true,
  30. changeOrigin: true,
  31. rewrite: (path) => path.replace(/^\/gitee/, ''),
  32. },
  33. },
  34. },
  35. build: {
  36. outDir: 'dist',
  37. sourcemap: false,
  38. cssCodeSplit: false,
  39. chunkSizeWarningLimit: 1500,
  40. rollupOptions: {
  41. output: {
  42. entryFileNames: `assets/[name].${new Date().getTime()}.js`,
  43. chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
  44. assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
  45. compact: true,
  46. manualChunks: {
  47. vue: ['vue', 'vue-router', 'pinia'],
  48. echarts: ['echarts'],
  49. },
  50. },
  51. },
  52. },
  53. css: { preprocessorOptions: { css: { charset: false } } },
  54. define: {
  55. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  56. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  57. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  58. },
  59. };
  60. });
  61. export default viteConfig;