Skip to content

Commit 00a74d9

Browse files
committed
chore: base rsbuild config
1 parent 8e78755 commit 00a74d9

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

rsbuild.base.config.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineConfig } from "@rsbuild/core";
2+
import { pluginTypeCheck } from "@rsbuild/plugin-type-check";
3+
import { pluginReact } from "@rsbuild/plugin-react";
4+
5+
export default defineConfig({
6+
source: {
7+
aliasStrategy: "prefer-tsconfig", // 'prefer-tsconfig' | 'prefer-alias'
8+
alias: {
9+
"@src": "./src",
10+
"@components": "./src/components",
11+
"@pages": "./src/pages",
12+
"@common": "./src/common",
13+
"@types": "./src/types",
14+
},
15+
include: ["src"],
16+
exclude: ["node_modules", "dist"],
17+
},
18+
plugins: [
19+
/**
20+
* [pluginReact description]
21+
*
22+
* React 插件提供了对 React 的支持,插件内部集成了 JSX 编译、React Refresh 等功能。
23+
* 默认情况下,Rsbuild 使用 React 17 引入的新版本 JSX runtime。
24+
*
25+
* 更多内容请参考官方文档 https://rsbuild.dev/zh/plugins/list/plugin-react
26+
*/
27+
pluginReact(),
28+
/**
29+
* [pluginTypeCheck description]
30+
*
31+
* 以下配置理论上不需要修改,保留默认设置即可。
32+
* 如果项目开启了 ts-loader,并且手动配置了 compileOnly: false,请关闭 Type Check 插件,避免重复类型检查。
33+
* 在 VS Code 等 IDE 中会将部分 error 显示成 warning,但在 fork-ts-checker-webpack-plugin 检查中仍会显示为 error
34+
* fork-ts-checker-webpack-plugin 不支持检查 .vue 组件中的 TypeScript 代码,如果你用的 vue,请参考官方文档
35+
*
36+
* 更多内容请参考官方文档 https://rsbuild.dev/zh/plugins/list/plugin-type-check
37+
*/
38+
pluginTypeCheck({
39+
// enable: true, //是否开启 TypeScript 类型检查,默认开启。
40+
// forkTsCheckerOptions: {}, //fork-ts-checker-webpack-plugin 配置项 https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#readme。
41+
}),
42+
],
43+
});

rsbuild.dev.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "@rsbuild/core";
2+
import { mergeRsbuildConfig } from "@rsbuild/core";
3+
import baseOptions from "./rsbuild.base.config";
4+
5+
const devOptions = defineConfig({
6+
plugins: [],
7+
});
8+
9+
export default mergeRsbuildConfig(baseOptions, devOptions);

rsbuild.config.ts renamed to rsbuild.prod.config.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { defineConfig } from "@rsbuild/core";
22
import { pluginTypeCheck } from "@rsbuild/plugin-type-check";
33
import { pluginReact } from "@rsbuild/plugin-react";
4+
import { mergeRsbuildConfig } from "@rsbuild/core";
45
import { pluginImageCompress } from "@rsbuild/plugin-image-compress";
6+
import baseOptions from "./rsbuild.base.config";
57
import { pluginCheckSyntax } from "@rsbuild/plugin-check-syntax";
68

7-
export default defineConfig({
9+
const prodOptions = defineConfig({
810
plugins: [
11+
/**
12+
* [pluginReact description]
13+
*
14+
* React 插件提供了对 React 的支持,插件内部集成了 JSX 编译、React Refresh 等功能。
15+
* 默认情况下,Rsbuild 使用 React 17 引入的新版本 JSX runtime。
16+
*
17+
* 更多内容请参考官方文档 https://rsbuild.dev/zh/plugins/list/plugin-react
18+
*/
919
pluginReact(),
1020
/**
1121
* [pluginImageCompress description]
@@ -33,9 +43,15 @@ export default defineConfig({
3343
* 目前语法检测是基于 AST parser 来实现的,每次检测时,只能找出文件中的第一个不兼容语法。
3444
* 如果一个文件中存在多个不兼容语法,你需要修复已发现的语法,并重新执行检测。
3545
* 如果日志中没有显示对应的源码位置,可以尝试将 output.disableMinimize 设置为 true 后再重新构建。
46+
* 一般来说使用默认设置就好,不需要额外配置。
47+
* 当前项目 package.json 中的 browserslist 配置会被用于检测,如果你需要更改检测的目标浏览器,可以通过 targets 字段进行配置。
3648
*
49+
* 更多内容请参考官方文档 https://rsbuild.dev/zh/plugins/list/plugin-check-syntax
3750
*/
38-
pluginCheckSyntax(),
51+
pluginCheckSyntax({
52+
// targets: ["chrome >= 58", "firefox >= 57", "safari >= 10", "edge >= 16", "ie >= 11"],
53+
// exclude: /node_modules\/**/,
54+
}),
3955
/**
4056
* [pluginTypeCheck description]
4157
*
@@ -52,3 +68,5 @@ export default defineConfig({
5268
}),
5369
],
5470
});
71+
72+
export default mergeRsbuildConfig(prodOptions, baseOptions);

0 commit comments

Comments
 (0)