vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. '@views': pathResolve('./src/views'),
  12. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  13. };
  14. const viteConfig = defineConfig((mode: ConfigEnv) => {
  15. const env = loadEnv(mode.mode, process.cwd());
  16. return {
  17. plugins: [
  18. vue(), vueJsx(), vueSetupExtend(),
  19. ],
  20. root: process.cwd(),
  21. resolve: {alias},
  22. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  23. optimizeDeps: {
  24. include: ['element-plus/es/locale/lang/zh-cn', 'element-plus/es/locale/lang/en', 'element-plus/es/locale/lang/zh-tw'],
  25. },
  26. server: {
  27. host: '0.0.0.0',
  28. port: env.VITE_PORT as unknown as number,
  29. open: true,
  30. hmr: true,
  31. proxy: {
  32. '/gitee': {
  33. target: 'https://gitee.com',
  34. ws: true,
  35. changeOrigin: true,
  36. rewrite: (path) => path.replace(/^\/gitee/, ''),
  37. },
  38. },
  39. },
  40. build: {
  41. outDir: 'dist',
  42. chunkSizeWarningLimit: 1500,
  43. rollupOptions: {
  44. output: {
  45. entryFileNames: `assets/[name].[hash].js`,
  46. chunkFileNames: `assets/[name].[hash].js`,
  47. assetFileNames: `assets/[name].[hash].[ext]`,
  48. compact: true,
  49. manualChunks: {
  50. vue: ['vue', 'vue-router', 'pinia'],
  51. echarts: ['echarts'],
  52. },
  53. },
  54. },
  55. },
  56. css: {preprocessorOptions: {css: {charset: false}}},
  57. define: {
  58. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  59. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  60. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  61. __VERSION__: JSON.stringify(process.env.npm_package_version),
  62. },
  63. };
  64. });
  65. export default viteConfig;