vite.config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. const pathResolve = (dir: string): any => {
  6. return resolve(__dirname, '.', dir);
  7. };
  8. const alias: Record<string, string> = {
  9. '/@': pathResolve('./src/'),
  10. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  11. };
  12. const viteConfig = defineConfig((mode: ConfigEnv) => {
  13. const env = loadEnv(mode.mode, process.cwd());
  14. return {
  15. plugins: [vue(), vueSetupExtend()],
  16. root: process.cwd(),
  17. resolve: { alias },
  18. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  19. hmr: true,
  20. optimizeDeps: {
  21. include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw'],
  22. },
  23. server: {
  24. host: '0.0.0.0',
  25. port: env.VITE_PORT as unknown as number,
  26. open: env.VITE_OPEN,
  27. proxy: {
  28. '/gitee': {
  29. target: 'https://gitee.com',
  30. ws: true,
  31. changeOrigin: true,
  32. rewrite: (path) => path.replace(/^\/gitee/, ''),
  33. },
  34. },
  35. },
  36. build: {
  37. outDir: 'dist',
  38. sourcemap: false,
  39. chunkSizeWarningLimit: 1500,
  40. rollupOptions: {
  41. output: {
  42. entryFileNames: `assets/[name].[hash].js`,
  43. chunkFileNames: `assets/[name].[hash].js`,
  44. assetFileNames: `assets/[name].[hash].[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. __VERSION__: JSON.stringify(process.env.npm_package_version),
  59. },
  60. };
  61. });
  62. export default viteConfig;