vite.config.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. template: {
  17. compilerOptions: {
  18. // 告诉Vue这些是原生自定义元素,不需要解析为Vue组件
  19. isCustomElement: (tag) => {
  20. // Blockly工具箱中使用的标签
  21. return ['block', 'category', 'field', 'shadow', 'value', 'sep', 'label'].includes(tag)
  22. }
  23. }
  24. }
  25. }),
  26. ],
  27. base: './',
  28. resolve: {
  29. // 路径别名配置
  30. alias: {
  31. '@': path.resolve(__dirname, './src')
  32. }
  33. },
  34. server: {
  35. host: '0.0.0.0',
  36. proxy: {
  37. '/admin-api': {
  38. // 使用加载的环境变量
  39. target: env.VITE_BASE_URL,
  40. changeOrigin: true
  41. }
  42. }
  43. },
  44. build: {
  45. outDir: 'aiWeb',
  46. rollupOptions: {
  47. output: {
  48. entryFileNames: `assets/[name]-[hash].js`,
  49. chunkFileNames: `assets/[name]-[hash].js`,
  50. // 保留原始目录结构
  51. assetFileNames: ({ name }) => {
  52. const extType = name.split('.').pop();
  53. if (/png|jpe?g|gif|svg|webp/i.test(extType)) {
  54. return `assets/images/[name]-[hash].[ext]`;
  55. }
  56. if (/woff2?|ttf|otf|eot/i.test(extType)) {
  57. return `assets/typeface/[name]-[hash].[ext]`;
  58. }
  59. if (/mp4/i.test(extType)) {
  60. return `assets/02video/[name]-[hash].[ext]`;
  61. }
  62. return `assets/[name]-[hash].[ext]`;
  63. }
  64. }
  65. }
  66. }
  67. }
  68. })