vite.config.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { defineConfig, loadEnv } from 'vite';
  2. import createVitePlugins from './vite/plugins';
  3. import path from 'path';
  4. export default defineConfig(({ mode, command }) => {
  5. const env = loadEnv(mode, process.cwd());
  6. const { VITE_APP_ENV } = env;
  7. return {
  8. plugins: createVitePlugins(env, command === 'build'),
  9. // 部署生产环境和开发环境下的URL。
  10. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  11. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  12. base: VITE_APP_ENV === 'production' ? '/' : '/',
  13. server: {
  14. port: 80,
  15. host: true,
  16. open: true,
  17. proxy: {
  18. // https://cn.vitejs.dev/config/#server-proxy
  19. '/dev-api': {
  20. target: 'http://localhost:8080',
  21. changeOrigin: true,
  22. rewrite: p => p.replace(/^\/dev-api/, ''),
  23. },
  24. },
  25. },
  26. resolve: {
  27. alias: {
  28. // 设置路径
  29. '~': path.resolve(__dirname, './'),
  30. // 设置别名
  31. '@': path.resolve(__dirname, './src'),
  32. },
  33. },
  34. build: {
  35. // chunkSizeWarningLimit: 1500,
  36. rollupOptions: {
  37. output: {
  38. manualChunks(id) {
  39. if (id.includes('element-plus/theme')) {
  40. return 'ele';
  41. }
  42. // if (id.includes('node_modules')) {
  43. // return id.toString().split('node_modules/.pnpm/')[1].split('/').toString();
  44. // }
  45. },
  46. },
  47. },
  48. minify: 'terser',
  49. terserOptions: {
  50. compress: {
  51. // eslint-disable-next-line camelcase
  52. drop_console: true,
  53. // eslint-disable-next-line camelcase
  54. drop_debugger: true,
  55. }
  56. },
  57. },
  58. };
  59. });