vite.config.ts 1.8 KB

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