base.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Vite 基础配置
  3. */
  4. import path from 'path';
  5. import { loadEnv } from 'vite';
  6. /**
  7. * 获取别名配置
  8. */
  9. export function getAlias(dirname) {
  10. return {
  11. '@': path.resolve(dirname, 'src'),
  12. '@components': path.resolve(dirname, 'src/components'),
  13. '@utils': path.resolve(dirname, 'src/utils'),
  14. '@api': path.resolve(dirname, 'src/api'),
  15. '@views': path.resolve(dirname, 'src/views'),
  16. '@stores': path.resolve(dirname, 'src/stores'),
  17. '@assets': path.resolve(dirname, 'src/assets'),
  18. '@style': path.resolve(dirname, 'src/style')
  19. };
  20. }
  21. /**
  22. * 获取服务器配置
  23. */
  24. export function getServerConfig(mode, cwd) {
  25. const env = loadEnv(mode, cwd);
  26. return {
  27. host: '0.0.0.0',
  28. port: parseInt(env.VITE_PORT || 3000),
  29. open: true,
  30. proxy: {
  31. '/dev-api': {
  32. target: 'http://localhost:8081',
  33. changeOrigin: true,
  34. rewrite: (path) => path.replace(/^\/dev-api/, ''),
  35. timeout: 30000,
  36. ws: true,
  37. retry: 0,
  38. configure: (proxy, options) => {
  39. proxy.on('error', (err) => {
  40. console.log('代理错误', err);
  41. });
  42. proxy.on('proxyReq', (proxyReq, req) => {
  43. // 修改请求头,禁用缓存
  44. proxyReq.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
  45. proxyReq.setHeader('Pragma', 'no-cache');
  46. proxyReq.setHeader('Expires', '0');
  47. });
  48. proxy.on('proxyRes', (proxyRes, req, res) => {
  49. // 修改响应头,禁用缓存
  50. proxyRes.headers['cache-control'] = 'no-cache, no-store, must-revalidate';
  51. proxyRes.headers['pragma'] = 'no-cache';
  52. proxyRes.headers['expires'] = '0';
  53. });
  54. }
  55. },
  56. },
  57. };
  58. }
  59. /**
  60. * 获取全局常量定义
  61. */
  62. export function getDefineConfig() {
  63. return {
  64. __VUE_PROD_DEVTOOLS__: false,
  65. __VUE_OPTIONS_API__: true,
  66. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
  67. };
  68. }
  69. /**
  70. * 获取依赖优化配置
  71. */
  72. export function getOptimizeDeps() {
  73. return {
  74. include: [
  75. 'vue',
  76. 'vue-router',
  77. 'pinia',
  78. 'dayjs',
  79. 'axios',
  80. 'js-cookie',
  81. 'nprogress'
  82. ],
  83. exclude: [
  84. '@wangeditor/editor',
  85. '@wangeditor/editor-for-vue',
  86. '@form-create/antd-designer',
  87. '@form-create/ant-design-vue',
  88. 'ant-design-vue',
  89. '@ant-design/icons-vue'
  90. ]
  91. };
  92. }