vite.config.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 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 = {
  17. plugins: [
  18. vue(),
  19. vueSetupExtend(),
  20. vueJsx(),
  21. ],
  22. root: process.cwd(),
  23. resolve: { alias },
  24. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  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. outDir: env.VITE_OUTPUT_DIR,
  44. chunkSizeWarningLimit: 1500,
  45. rollupOptions: {
  46. output: {
  47. entryFileNames: `assets/[name].[hash].js`,
  48. chunkFileNames: `assets/[name].[hash].js`,
  49. assetFileNames: `assets/[name].[hash].[ext]`,
  50. // compact: true,
  51. manualChunks: {
  52. vue: ['vue', 'vue-router', 'pinia'],
  53. echarts: ['echarts'],
  54. },
  55. },
  56. },
  57. sourcemap: true,
  58. },
  59. css: { preprocessorOptions: { css: { charset: false } } },
  60. define: {
  61. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  62. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  63. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  64. __VERSION__: JSON.stringify(process.env.npm_package_version),
  65. },
  66. }
  67. return config
  68. })
  69. export default viteConfig