vite.config.js 2.0 KB

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