vite.config.ts 2.6 KB

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