1e9ff8a0de
- migrate the classic frontend from Vite to Rsbuild with JSX, Semi UI, proxy, and production build config. - update make dev-web to run both default and classic frontends for local theme switching. - fix classic public page height, footer, CORS proxy, error handling, and constant export warnings. - update Dockerfile and release workflow to install from the web workspace root with the shared lockfile.
105 lines
3.0 KiB
TypeScript
Vendored
105 lines
3.0 KiB
TypeScript
Vendored
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
import { defineConfig, loadEnv } from '@rsbuild/core'
|
|
import { pluginReact } from '@rsbuild/plugin-react'
|
|
import { tanstackRouter } from '@tanstack/router-plugin/rspack'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
export default defineConfig(({ envMode }) => {
|
|
const env = loadEnv({ mode: envMode, prefixes: ['VITE_'] })
|
|
const serverUrl =
|
|
process.env.VITE_REACT_APP_SERVER_URL ||
|
|
env.rawPublicVars.VITE_REACT_APP_SERVER_URL ||
|
|
'http://localhost:3000'
|
|
|
|
const isProd = envMode === 'production'
|
|
const devProxy = Object.fromEntries(
|
|
(['/api', '/mj', '/pg'] as const).map((key) => [
|
|
key,
|
|
{ target: serverUrl, changeOrigin: true },
|
|
]),
|
|
) as Record<string, { target: string; changeOrigin: boolean }>
|
|
|
|
return {
|
|
plugins: [pluginReact()],
|
|
// Rsbuild 2: replaces deprecated `performance.chunkSplit` (RSPack 2 aligned)
|
|
splitChunks: {
|
|
preset: 'default',
|
|
cacheGroups: {
|
|
'vendor-react': {
|
|
test: /node_modules[\\/](react|react-dom)[\\/]/,
|
|
name: 'vendor-react',
|
|
chunks: 'all',
|
|
priority: 0,
|
|
enforce: true,
|
|
},
|
|
'vendor-ui-primitives': {
|
|
test: /node_modules[\\/](@base-ui|@radix-ui)[\\/]/,
|
|
name: 'vendor-ui-primitives',
|
|
chunks: 'all',
|
|
priority: 0,
|
|
enforce: true,
|
|
},
|
|
'vendor-tanstack': {
|
|
test: /node_modules[\\/]@tanstack[\\/]/,
|
|
name: 'vendor-tanstack',
|
|
chunks: 'all',
|
|
priority: 0,
|
|
enforce: true,
|
|
},
|
|
},
|
|
},
|
|
source: {
|
|
entry: {
|
|
index: './src/main.tsx',
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
html: {
|
|
template: './index.html',
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
strictPort: true,
|
|
proxy: devProxy,
|
|
},
|
|
output: {
|
|
// Production optimizations
|
|
minify: isProd,
|
|
target: 'web',
|
|
distPath: {
|
|
root: 'dist',
|
|
},
|
|
// Rely on Rsbuild default legalComments ("linked" → per-chunk *.LICENSE.txt) in all modes.
|
|
// Do not set "none" in production: that strips minifier-preserved third-party notices and
|
|
// extracted license files, which some distributions require for open-source compliance.
|
|
},
|
|
performance: {
|
|
// Remove console in production
|
|
removeConsole: isProd ? ['log'] : false,
|
|
// Speed up repeated `rsbuild build` (local + CI when node_modules/.cache is preserved).
|
|
// @see https://v2.rsbuild.dev/config/performance/build-cache
|
|
buildCache: {
|
|
cacheDigest: [process.env.VITE_REACT_APP_VERSION],
|
|
},
|
|
},
|
|
tools: {
|
|
rspack: {
|
|
plugins: [
|
|
tanstackRouter({
|
|
target: 'react',
|
|
// Dev: avoid per-route async chunks (reduces white flash on navigation + faster HMR feedback).
|
|
// Prod: keep route-based code splitting.
|
|
autoCodeSplitting: isProd,
|
|
}),
|
|
],
|
|
},
|
|
},
|
|
}
|
|
})
|