vite.config.ts 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { defineConfig } from 'vite'
  2. import react from '@vitejs/plugin-react'
  3. import path from 'path'
  4. import fs from 'fs'
  5. // 检测SSL证书是否存在
  6. const sslKeyPath = path.resolve(__dirname, '../ssl/key.pem')
  7. const sslCertPath = path.resolve(__dirname, '../ssl/cert.pem')
  8. const hasSSL = fs.existsSync(sslKeyPath) && fs.existsSync(sslCertPath)
  9. // https://vitejs.dev/config/
  10. export default defineConfig({
  11. plugins: [react()],
  12. resolve: {
  13. alias: {
  14. '@': path.resolve(__dirname, './src'),
  15. },
  16. },
  17. server: {
  18. port: 5173,
  19. host: true, // 允许通过IP访问(0.0.0.0)
  20. // 自动启用HTTPS(如果证书存在)
  21. https: hasSSL ? {
  22. key: fs.readFileSync(sslKeyPath),
  23. cert: fs.readFileSync(sslCertPath),
  24. } : false,
  25. },
  26. build: {
  27. outDir: 'dist',
  28. sourcemap: false,
  29. rollupOptions: {
  30. output: {
  31. manualChunks: {
  32. 'react-vendor': ['react', 'react-dom'],
  33. 'recorder': ['recorder-core'],
  34. },
  35. },
  36. },
  37. },
  38. })