rsbuild.config.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import path from 'node:path'
  2. import { fileURLToPath } from 'node:url'
  3. import { defineConfig, loadEnv } from '@rsbuild/core'
  4. import { pluginReact } from '@rsbuild/plugin-react'
  5. import { pluginTailwindcss } from '@rsbuild/plugin-tailwindcss'
  6. import { tanstackRouter } from '@tanstack/router-plugin/rspack'
  7. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  8. export default defineConfig(({ envMode }) => {
  9. const env = loadEnv({ mode: envMode, prefixes: ['VITE_'] })
  10. const serverUrl =
  11. process.env.VITE_REACT_APP_SERVER_URL ||
  12. env.rawPublicVars.VITE_REACT_APP_SERVER_URL ||
  13. // 'http://192.168.100.26:3000',
  14. 'http://47.117.92.63:8081'
  15. // 'http://192.168.100.184:3000'
  16. // 'http://192.168.20.70:3000'
  17. const isProd = envMode === 'production'
  18. const devProxy = Object.fromEntries(
  19. (['/api', '/mj', '/pg'] as const).map((key) => [
  20. key,
  21. { target: serverUrl, changeOrigin: true },
  22. ])
  23. ) as Record<string, { target: string; changeOrigin: boolean }>
  24. return {
  25. plugins: [pluginReact(), pluginTailwindcss({ optimize: false })],
  26. // Rsbuild 2: replaces deprecated `performance.chunkSplit` (RSPack 2 aligned)
  27. splitChunks: {
  28. preset: 'default',
  29. cacheGroups: {
  30. 'vendor-react': {
  31. test: /node_modules[\\/](react|react-dom)[\\/]/,
  32. name: 'vendor-react',
  33. chunks: 'all',
  34. priority: 0,
  35. enforce: true,
  36. },
  37. 'vendor-ui-primitives': {
  38. test: /node_modules[\\/](@base-ui|@radix-ui)[\\/]/,
  39. name: 'vendor-ui-primitives',
  40. chunks: 'all',
  41. priority: 0,
  42. enforce: true,
  43. },
  44. 'vendor-tanstack': {
  45. test: /node_modules[\\/]@tanstack[\\/]/,
  46. name: 'vendor-tanstack',
  47. chunks: 'all',
  48. priority: 0,
  49. enforce: true,
  50. },
  51. },
  52. },
  53. source: {
  54. entry: {
  55. index: './src/main.tsx',
  56. },
  57. },
  58. resolve: {
  59. alias: {
  60. '@': path.resolve(__dirname, './src'),
  61. },
  62. },
  63. html: {
  64. template: './index.html',
  65. },
  66. server: {
  67. host: '0.0.0.0',
  68. strictPort: false,
  69. proxy: devProxy,
  70. },
  71. output: {
  72. // Production optimizations
  73. minify: isProd,
  74. target: 'web',
  75. distPath: {
  76. root: 'dist',
  77. },
  78. // Rely on Rsbuild default legalComments ("linked" → per-chunk *.LICENSE.txt) in all modes.
  79. // Do not set "none" in production: that strips minifier-preserved third-party notices and
  80. // extracted license files, which some distributions require for open-source compliance.
  81. },
  82. performance: {
  83. // Remove console in production
  84. removeConsole: isProd ? ['log'] : false,
  85. buildCache: false,
  86. },
  87. tools: {
  88. rspack: {
  89. plugins: [
  90. tanstackRouter({
  91. target: 'react',
  92. // Dev: avoid per-route async chunks (reduces white flash on navigation + faster HMR feedback).
  93. // Prod: keep route-based code splitting.
  94. autoCodeSplitting: isProd,
  95. }),
  96. ],
  97. },
  98. },
  99. }
  100. })