vite.config.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. },
  43. },
  44. build: {
  45. outDir: 'dist',
  46. chunkSizeWarningLimit: 1500,
  47. sourcemap: false,
  48. rollupOptions: {
  49. output: {
  50. chunkFileNames: 'assets/js/[name]-[hash].js',
  51. entryFileNames: 'assets/js/[name]-[hash].js',
  52. assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
  53. manualChunks(id) {
  54. if (id.includes('node_modules')) {
  55. return id.toString().match(/\/node_modules\/(?!.pnpm)(?<moduleName>[^\/]*)\//)?.groups!.moduleName ?? 'vender'
  56. }
  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. __NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
  67. __NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
  68. },
  69. }
  70. })
  71. export default viteConfig