vite.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import react from '@vitejs/plugin-react';
  2. import { defineConfig, transformWithEsbuild } from 'vite';
  3. import pkg from '@douyinfe/vite-plugin-semi';
  4. const { vitePluginSemi } = pkg;
  5. // https://vitejs.dev/config/
  6. export default defineConfig({
  7. plugins: [
  8. {
  9. name: 'treat-js-files-as-jsx',
  10. async transform(code, id) {
  11. if (!/src\/.*\.js$/.test(id)) {
  12. return null;
  13. }
  14. // Use the exposed transform from vite, instead of directly
  15. // transforming with esbuild
  16. return transformWithEsbuild(code, id, {
  17. loader: 'jsx',
  18. jsx: 'automatic',
  19. });
  20. },
  21. },
  22. react(),
  23. vitePluginSemi({
  24. cssLayer: true
  25. })
  26. ],
  27. optimizeDeps: {
  28. force: true,
  29. esbuildOptions: {
  30. loader: {
  31. '.js': 'jsx',
  32. '.json': 'json',
  33. },
  34. },
  35. },
  36. build: {
  37. rollupOptions: {
  38. output: {
  39. manualChunks: {
  40. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  41. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  42. semantic: ['semantic-ui-offline', 'semantic-ui-react'],
  43. visactor: ['@visactor/react-vchart', '@visactor/vchart'],
  44. tools: ['axios', 'history', 'marked'],
  45. 'react-components': [
  46. 'react-dropzone',
  47. 'react-fireworks',
  48. 'react-telegram-login',
  49. 'react-toastify',
  50. 'react-turnstile',
  51. ],
  52. i18n: [
  53. 'i18next',
  54. 'react-i18next',
  55. 'i18next-browser-languagedetector',
  56. ],
  57. },
  58. },
  59. },
  60. },
  61. server: {
  62. host: '0.0.0.0',
  63. proxy: {
  64. '/api': {
  65. target: 'http://localhost:3000',
  66. changeOrigin: true,
  67. },
  68. '/pg': {
  69. target: 'http://localhost:3000',
  70. changeOrigin: true,
  71. },
  72. },
  73. },
  74. });