vite.config.ts 2.1 KB

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