vite.config.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import qiankun from 'vite-plugin-qiankun'
  6. // https://vite.dev/config/
  7. export default defineConfig(({ mode }) => {
  8. // 根据环境变量设置 base
  9. const base = mode === 'release' ? '/saas/form/' : '/'
  10. return {
  11. plugins: [
  12. vue(),
  13. vueJsx(),
  14. qiankun('curstom-form', {
  15. useDevMode: true, // 开发模式下使用热更新
  16. }),
  17. ],
  18. resolve: {
  19. alias: {
  20. '@': fileURLToPath(new URL('./src', import.meta.url)),
  21. },
  22. },
  23. server: {
  24. port: 5173,
  25. cors: true,
  26. },
  27. base,
  28. build: {
  29. target: 'esnext',
  30. outDir: 'form',
  31. chunkSizeWarningLimit: 1000,
  32. terserOptions: {
  33. compress: {
  34. drop_console: true,
  35. drop_debugger: true,
  36. },
  37. },
  38. rollupOptions: {
  39. output: {
  40. sourcemap: mode !== 'production',
  41. assetFileNames: 'static/[name].[hash].[ext]', // 确保静态资源路径正确
  42. chunkFileNames: () => {
  43. return 'static/[name].[hash].js'
  44. },
  45. entryFileNames: 'static/[name].[hash].js',
  46. cssChunkFileNames: 'static/[name].[hash].css',
  47. },
  48. },
  49. },
  50. }
  51. })