vite.config.ts 2.4 KB

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