vite.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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-plus'
  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. threshold: 5121,
  22. disable: !env.VITE_COMPRESSION,
  23. deleteOriginFile: false,
  24. }),
  25. ],
  26. root: process.cwd(),
  27. resolve: { alias },
  28. base: command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  29. hmr: true,
  30. optimizeDeps: { exclude: ['vue-demi'] },
  31. server: {
  32. host: '0.0.0.0',
  33. port: env.VITE_PORT,
  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. '/api': {
  43. target: 'http://localhost:9999/',
  44. ws: true,
  45. changeOrigin: true,
  46. rewrite: (path) => path.replace(/^\/api/, ''),
  47. },
  48. },
  49. },
  50. build: {
  51. outDir: 'dist',
  52. chunkSizeWarningLimit: 1500,
  53. sourcemap: false,
  54. rollupOptions: {
  55. output: {
  56. chunkFileNames: 'assets/js/[name]-[hash].js',
  57. entryFileNames: 'assets/js/[name]-[hash].js',
  58. assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
  59. manualChunks(id) {
  60. if (id.includes('node_modules')) {
  61. return id.toString().match(/\/node_modules\/(?!.pnpm)(?<moduleName>[^\/]*)\//)?.groups!.moduleName ?? 'vender'
  62. }
  63. },
  64. },
  65. },
  66. },
  67. css: { preprocessorOptions: { css: { charset: false } } },
  68. define: {
  69. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  70. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  71. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  72. __NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
  73. __NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
  74. },
  75. }
  76. })
  77. export default viteConfig