vite.config.ts 1.8 KB

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