vite.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import react from '@vitejs/plugin-react';
  2. import { defineConfig, transformWithEsbuild } from 'vite';
  3. // https://vitejs.dev/config/
  4. export default defineConfig({
  5. plugins: [
  6. {
  7. name: 'treat-js-files-as-jsx',
  8. async transform(code, id) {
  9. if (!/src\/.*\.js$/.test(id)) {
  10. return null;
  11. }
  12. // Use the exposed transform from vite, instead of directly
  13. // transforming with esbuild
  14. return transformWithEsbuild(code, id, {
  15. loader: 'jsx',
  16. jsx: 'automatic',
  17. });
  18. },
  19. },
  20. react(),
  21. {
  22. name: 'semi-css-layer',
  23. transformIndexHtml(html) {
  24. // Add layer to Semi CSS by prepending style tag
  25. return html.replace(
  26. /<\/head>/,
  27. `<style>@layer tailwind-base,semi,tailwind-components,tailwind-utils;</style></head>`
  28. );
  29. },
  30. transform(code, id) {
  31. if (id.includes('@douyinfe/semi-ui') && id.endsWith('.css')) {
  32. // Wrap Semi CSS in a layer
  33. return {
  34. code: `@layer semi { ${code} }`,
  35. map: null
  36. };
  37. }
  38. return null;
  39. }
  40. }
  41. ],
  42. optimizeDeps: {
  43. force: true,
  44. esbuildOptions: {
  45. loader: {
  46. '.js': 'jsx',
  47. '.json': 'json',
  48. },
  49. },
  50. },
  51. build: {
  52. rollupOptions: {
  53. output: {
  54. manualChunks: {
  55. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  56. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  57. semantic: ['semantic-ui-offline', 'semantic-ui-react'],
  58. visactor: ['@visactor/react-vchart', '@visactor/vchart'],
  59. tools: ['axios', 'history', 'marked'],
  60. 'react-components': [
  61. 'react-dropzone',
  62. 'react-fireworks',
  63. 'react-telegram-login',
  64. 'react-toastify',
  65. 'react-turnstile',
  66. ],
  67. i18n: [
  68. 'i18next',
  69. 'react-i18next',
  70. 'i18next-browser-languagedetector',
  71. ],
  72. },
  73. },
  74. },
  75. },
  76. server: {
  77. host: '0.0.0.0',
  78. proxy: {
  79. '/api': {
  80. target: 'http://localhost:3000',
  81. changeOrigin: true,
  82. },
  83. '/pg': {
  84. target: 'http://localhost:3000',
  85. changeOrigin: true,
  86. },
  87. },
  88. },
  89. });