vite.config.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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) => {
  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. 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. hmr: true,
  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. chunkSizeWarningLimit: 1500,
  39. rollupOptions: {
  40. output: {
  41. entryFileNames: `assets/[name].[hash].js`,
  42. chunkFileNames: `assets/[name].[hash].js`,
  43. assetFileNames: `assets/[name].[hash].[ext]`,
  44. compact: true,
  45. manualChunks: {
  46. vue: ['vue', 'vue-router', 'pinia'],
  47. echarts: ['echarts'],
  48. },
  49. },
  50. },
  51. },
  52. css: { preprocessorOptions: { css: { charset: false } } },
  53. define: {
  54. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  55. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  56. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  57. __VERSION__: JSON.stringify(process.env.npm_package_version),
  58. },
  59. };
  60. });
  61. export default viteConfig;