vite.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. // 引入@vitejs/plugin-legacy
  5. import legacy from '@vitejs/plugin-legacy'
  6. // https://vite.dev/config/
  7. export default defineConfig(({ mode }) => {
  8. // 加载对应模式的环境变量
  9. const env = loadEnv(mode, process.cwd())
  10. return {
  11. plugins: [
  12. legacy({
  13. targets: ['defaults', 'not IE 11']
  14. }),
  15. vue(),
  16. ],
  17. base: './',
  18. resolve: {
  19. // 路径别名配置
  20. alias: {
  21. '@': path.resolve(__dirname, './src')
  22. }
  23. },
  24. server: {
  25. host: '0.0.0.0',
  26. proxy: {
  27. '/admin-api': {
  28. // 使用加载的环境变量
  29. target: env.VITE_BASE_URL,
  30. changeOrigin: true
  31. }
  32. }
  33. },
  34. build: {
  35. outDir: 'aiWeb',
  36. rollupOptions: {
  37. output: {
  38. entryFileNames: `assets/[name]-[hash].js`,
  39. chunkFileNames: `assets/[name]-[hash].js`,
  40. // 保留原始目录结构
  41. assetFileNames: ({ name }) => {
  42. const extType = name.split('.').pop();
  43. if (/png|jpe?g|gif|svg|webp/i.test(extType)) {
  44. return `assets/images/[name]-[hash].[ext]`;
  45. }
  46. if (/woff2?|ttf|otf|eot/i.test(extType)) {
  47. return `assets/typeface/[name]-[hash].[ext]`;
  48. }
  49. if (/mp4/i.test(extType)) {
  50. return `assets/02video/[name]-[hash].[ext]`;
  51. }
  52. return `assets/[name]-[hash].[ext]`;
  53. }
  54. }
  55. }
  56. }
  57. }
  58. })