vite.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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, VITE_BASE_PATH } = 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_BASE_PATH,
  13. server: {
  14. port: 3001,
  15. host: true,
  16. open: true,
  17. proxy: {
  18. // https://cn.vitejs.dev/config/#server-proxy
  19. '/dev-api': {
  20. target: 'https://hnapi.kdboss.cn', //正式
  21. // target: 'http://211.149.199.65:5007', //测试
  22. ws: true,
  23. changeOrigin: true,
  24. rewrite: (p) => p.replace(/^\/dev-api/, ''),
  25. },
  26. },
  27. },
  28. resolve: {
  29. alias: {
  30. // 设置路径
  31. '~': path.resolve(__dirname, './'),
  32. // 设置别名
  33. '@': path.resolve(__dirname, './src'),
  34. '@assets': path.resolve(__dirname, './src/assets'),
  35. '@comps': path.resolve(__dirname, './src/components'),
  36. '@utils': path.resolve(__dirname, './src/utils'),
  37. '@store': path.resolve(__dirname, './src/store'),
  38. '@apis': path.resolve(__dirname, './src/api'),
  39. '@views': path.resolve(__dirname, './src/views'),
  40. '@hooks': path.resolve(__dirname, './src/hooks'),
  41. },
  42. },
  43. build: {
  44. outDir: 'hn-kdbooss-admin-dist', // 这里可以指定你想要的打包文件夹名
  45. rollupOptions: {
  46. output: {
  47. manualChunks(id) {
  48. if (id.includes('element-plus/theme')) {
  49. return 'ele'
  50. }
  51. },
  52. },
  53. }
  54. },
  55. }
  56. })