| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import path from 'path'
- import { createRequire } from 'module'
- import { fileURLToPath } from 'url'
- import { defineConfig, loadEnv } from '@rsbuild/core'
- import { pluginReact } from '@rsbuild/plugin-react'
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
- const require = createRequire(import.meta.url)
- const semiUiDir = path.resolve(
- path.dirname(require.resolve('@douyinfe/semi-ui')),
- '../..',
- )
- export default defineConfig(({ envMode }) => {
- const env = loadEnv({ mode: envMode, prefixes: ['VITE_'] })
- const clientServerUrl =
- process.env.VITE_REACT_APP_SERVER_URL ||
- env.rawPublicVars.VITE_REACT_APP_SERVER_URL ||
- ''
- const proxyServerUrl =
- clientServerUrl ||
- 'http://localhost:3000'
- const isProd = envMode === 'production'
- const devProxy = Object.fromEntries(
- (['/api', '/mj', '/pg'] as const).map((key) => [
- key,
- { target: proxyServerUrl, changeOrigin: true },
- ]),
- ) as Record<string, { target: string; changeOrigin: boolean }>
- return {
- plugins: [pluginReact()],
- source: {
- entry: {
- index: './src/index.jsx',
- },
- define: {
- 'import.meta.env.VITE_REACT_APP_SERVER_URL': JSON.stringify(
- clientServerUrl,
- ),
- },
- },
- resolve: {
- alias: {
- '@': path.resolve(__dirname, './src'),
- '@douyinfe/semi-ui/dist/css/semi.css': path.resolve(
- semiUiDir,
- 'dist/css/semi.css',
- ),
- },
- },
- html: {
- template: './index.html',
- },
- server: {
- host: '0.0.0.0',
- strictPort: false,
- proxy: devProxy,
- },
- output: {
- minify: isProd,
- target: 'web',
- distPath: {
- root: 'dist',
- },
- },
- performance: {
- removeConsole: isProd ? ['log'] : false,
- buildCache: {
- cacheDigest: [process.env.VITE_REACT_APP_VERSION],
- },
- },
- tools: {
- rspack: {
- module: {
- rules: [
- {
- test: /src[\\/].*\.js$/,
- type: 'javascript/auto',
- use: [
- {
- loader: 'builtin:swc-loader',
- options: {
- jsc: {
- parser: {
- syntax: 'ecmascript',
- jsx: true,
- },
- transform: {
- react: {
- runtime: 'automatic',
- development: !isProd,
- refresh: !isProd,
- },
- },
- },
- },
- },
- ],
- },
- ],
- },
- },
- },
- }
- })
|