forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsbuild.config.ts
More file actions
102 lines (97 loc) · 2.93 KB
/
Copy pathrsbuild.config.ts
File metadata and controls
102 lines (97 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig, loadEnv } from '@rsbuild/core'
import { pluginReact } from '@rsbuild/plugin-react'
import { pluginTailwindcss } from '@rsbuild/plugin-tailwindcss'
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(), pluginTailwindcss({ optimize: false })],
// 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: false,
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,
buildCache: false,
},
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,
}),
],
},
},
}
})