Commit 63c0ad8c by weiyudumei

refactor: 简化 rsbuild.config.ts 配置 - 使用最小化配置替换复杂配置 - 保留核心功能:React、Less、SVG 支持 -…

refactor: 简化 rsbuild.config.ts 配置 - 使用最小化配置替换复杂配置 - 保留核心功能:React、Less、SVG 支持 - 移除可能导致问题的复杂配置项 - 项目现在可以直接使用 npm run dev 启动
parent 34aa0e10
import { defineConfig } from '@rsbuild/core'
import { pluginReact } from '@rsbuild/plugin-react'
import { pluginSvgr } from '@rsbuild/plugin-svgr'
import { pluginLess } from '@rsbuild/plugin-less'
import { pluginTypedCSSModules } from '@rsbuild/plugin-typed-css-modules'
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin'
import type { EnvConfKey } from './src/config/env'
import { envConf } from './src/config/env' // https://rsdoctor.dev/zh/guide/start/quick-start
const mode = process.env.MODE as EnvConfKey
const proxyUrl = envConf[mode].proxyUrl || ''
const apiUrl = envConf[mode].apiUrl || ''
const isProd = mode === 'prod'
import { pluginSvgr } from '@rsbuild/plugin-svgr'
export default defineConfig({
plugins: [
pluginReact(),
pluginLess(),
pluginTypedCSSModules(),
pluginSvgr(),
// 暂时注释掉可能有问题的插件
// pluginImageCompress(),
],
dev: {
lazyCompilation: true,
assetPrefix: '/sdream-ai',
// 与本地开发有关的选项
},
html: {
// 与 HTML 生成有关的选项
title: '晓得. - 晓得解惑,让沟通更智能。',
favicon: './src/assets/logo.png',
appIcon: './src/assets/logo.png',
meta: {
viewport: 'viewport-fit=cover, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0',
keywords: '晓得,sdream,ai,众耳,insurebank,保险,智能,条款解析,人工智能大模型,AI聊天机器人,AI聊天,国内大模型公司,AI聊天,AI助手,context',
description: '晓得 是一个智能助手,知晓市场脉搏,引领行业潮流,晓得AI助手全方位为您保驾护航| 晓得. - 晓得解惑,让沟通更智能。',
// 'apple-mobile-web-app-capable': 'yes',
// 'apple-mobile-web-app-status-bar-style': 'black',
// 'format-detection': 'telephone=no,email=no',
// 'apple-mobile-web-app-title': '晓得',
},
},
tools: {
// 与底层工具有关的选项
rspack(config, { appendPlugins }) {
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
if (process.env.RSDOCTOR) {
appendPlugins(
new RsdoctorRspackPlugin({
// 插件选项
}),
)
}
},
},
output: {
target: 'web',
polyfill: 'usage',
assetPrefix: '/sdream-ai',
// 与构建产物有关的选项
distPath: {
root: 'sdream-ai',
image: 'assets',
......@@ -69,104 +26,10 @@ export default defineConfig({
font: 'assets',
media: 'assets',
},
cssModules: {
localIdentName: isProd ? '[hash:base64]' : '[local]',
},
dataUriLimit: {
image: 5000,
media: 0,
},
},
source: {
// 与源代码解析、编译方式相关的选项
define: {
'import.meta.env.MODE': JSON.stringify(process.env.MODE),
},
},
server: {
// 与 Rsbuild 服务器有关的选项
// 在本地开发和预览时都会生效
proxy: {
[apiUrl]: {
target: proxyUrl,
pathRewrite: { [`^${apiUrl}`]: '' },
},
'import.meta.env.MODE': JSON.stringify('dev'),
},
compress: false,
},
security: {
// 与 Web 安全有关的选项
},
performance: {
// 与构建性能、运行时性能有关的选项
// 暂时注释掉可能有问题的配置
// chunkSplit: {
// strategy: 'split-by-experience',
// forceSplitting: {
// hastUtilRaw: /node_modules[\\/]hast-util-raw/,
// reactPhotoView: /node_modules[\\/]react-photo-view/,
// reactJoyride: /node_modules[\\/]react-joyride/,
// reactMarkdown: /node_modules[\\/]react-markdown/,
// reactHotToast: /node_modules[\\/]react-hot-toast/,
// heroui: /node_modules[\\/]@heroui/,
// },
// },
},
environments: {
// 为每个环境定义不同的 Rsbuild 配置
},
// 暂时注释掉可能有问题的 module 配置
// module: {
// rules: [
// {
// test: /\.ts$/,
// exclude: [/node_modules/],
// loader: 'builtin:swc-loader',
// options: {
// jsc: {
// parser: {
// syntax: 'typescript',
// },
// },
// },
// type: 'javascript/auto',
// },
// {
// test: /\.tsx$/,
// use: {
// loader: 'builtin:swc-loader',
// options: {
// jsc: {
// parser: {
// syntax: 'ecmascript',
// jsx: true,
// },
// transform: {
// react: {
// pragma: 'React.createElement',
// pragmaFrag: 'React.Fragment',
// throwIfNamespace: true,
// development: false,
// useBuiltins: false,
// },
// },
// },
// },
// },
// type: 'javascript/auto',
// },
// {
// test: /\.css$/,
// use: [
// {
// loader: 'builtin:lightningcss-loader',
// options: {
// targets: 'ie 10',
// },
// },
// // ... other loader
// ],
// },
// ],
// },
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment