vite.config.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. 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. },
  58. };
  59. });
  60. export default viteConfig;