vite.config.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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: {
  31. include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw'],
  32. },
  33. server: {
  34. host: '0.0.0.0',
  35. port: env.VITE_PORT,
  36. open: env.VITE_OPEN,
  37. proxy: {
  38. '/gitee': {
  39. target: 'https://gitee.com',
  40. ws: true,
  41. changeOrigin: true,
  42. rewrite: (path) => path.replace(/^\/gitee/, ''),
  43. },
  44. },
  45. },
  46. build: {
  47. chunkSizeWarningLimit: 1500,
  48. outDir: 'dist',
  49. sourcemap: false,
  50. rollupOptions: {
  51. output: {
  52. assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
  53. chunkFileNames: 'assets/js/[name]-[hash].js',
  54. entryFileNames: 'assets/js/[name]-[hash].js',
  55. manualChunks(id) {
  56. if (id.includes('node_modules')) {
  57. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  58. }
  59. },
  60. },
  61. },
  62. },
  63. css: { preprocessorOptions: { css: { charset: false } } },
  64. define: {
  65. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  66. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  67. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  68. __NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
  69. __NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
  70. },
  71. }
  72. })
  73. export default viteConfig