You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/guide/basic/configure-rslib.mdx
+48-69Lines changed: 48 additions & 69 deletions
Original file line number
Diff line number
Diff line change
@@ -6,89 +6,69 @@ If you need to customize build behaviors, you can read the following sections to
6
6
7
7
## Configuration Structure
8
8
9
-
The configuration structure of Rslib looks like this:
9
+
Rslib provides the `lib` option to configure the library outputs. It is an array, and each object is used to describe a format of the output.
10
+
11
+
For example, output ESM and CJS formats, and use `es2021` syntax:
12
+
13
+
```js title="rslib.config.mjs"
14
+
exportdefault {
15
+
lib: [
16
+
{ format:'esm', syntax:'es2021' },
17
+
{ format:'cjs', syntax:'es2021' },
18
+
],
19
+
};
20
+
```
21
+
22
+
### Common Rsbuild Configurations
23
+
24
+
You can set common Rsbuild configurations outside the `lib` field, which will be inherited by each configuration object inside the `lib` field.
25
+
26
+
For example, set the [output.target](/config/rsbuild/output#outputtarget) of Rsbuild to `web`, which will affect the output of all `lib` configuration objects:
10
27
11
28
```js title="rslib.config.mjs"
12
29
exportdefault {
13
-
// Array of Lib configurations.
14
-
// Each object represents a set of independent configurations for each output format.
15
-
// Distinct configurations can be specified in each object, which is a superset of Rsbuild configurations along with Rslib's specific configurations.
16
30
lib: [
17
-
// The first set of Lib configurations
31
+
{ format:'esm', syntax:'es2021' },
32
+
{ format:'cjs', syntax:'es2021' },
33
+
],
34
+
output: {
35
+
target:'web',
36
+
},
37
+
};
38
+
```
39
+
40
+
### Separate Rsbuild Configurations
41
+
42
+
In the `lib` field, you can set separate Rsbuild configurations for each output format, which will override the common Rsbuild configurations outside the `lib` field.
43
+
44
+
For example, separately set the [output.target](/config/rsbuild/output#outputtarget) of the ESM output to `web`:
45
+
46
+
```js title="rslib.config.mjs"
47
+
exportdefault {
48
+
lib: [
49
+
// The target of the ESM output is `web`
18
50
{
19
-
// Independent Rslib specific configurations
20
-
format:'esm', // options for the output format of JavaScript files
21
-
bundle:true, // options for the build type
22
-
autoExtension:true, // options for the extensions of JavaScript files
23
-
syntax:'esnext', // options for the target syntax
24
-
externalHelpers:false, // options for externalizing helper functions
25
-
umdName:'RslibUmdExample', // options for the export name of the UMD library
26
-
autoExternal: {
27
-
// options for automatically externalizing third-party dependencies
28
-
},
29
-
redirect: {
30
-
// options for redirecting import paths
31
-
},
32
-
dts: {
33
-
// options for generating TypeScript declaration files
34
-
},
35
-
shims: {
36
-
// options for compatibility shims
37
-
},
38
-
banner: {
39
-
// options for the file banner
40
-
},
41
-
footer: {
42
-
// options for the file footer
43
-
},
44
-
// Independent Rsbuild configurations
51
+
format:'esm',
45
52
output: {
46
-
// options for build outputs
53
+
target:'web',
47
54
},
48
-
source: {
49
-
// options for source code parsing and compilation
50
-
},
51
-
tools: {
52
-
// options for the low-level tools
53
-
},
54
-
plugins: [
55
-
// configure Rsbuild plugins
56
-
],
57
-
// other independent Rsbuild configurations
58
55
},
56
+
// The CJS output inherits the common configuration and target is `node`
59
57
{
60
-
// The second set of Lib configurations
61
58
format:'cjs',
62
-
// ... other independent Rslib specific configurations and Rsbuild configurations
63
59
},
64
-
// ... Additional sets of Lib configurations (if needed)
65
60
],
66
-
// Shared Rsbuild configurations
67
61
output: {
68
-
// options for build outputs
69
-
},
70
-
source: {
71
-
// options for source code parsing and compilation
72
-
},
73
-
tools: {
74
-
// options for the low-level tools
62
+
target:'node',
75
63
},
76
-
plugins: [
77
-
// configure Rsbuild plugins
78
-
],
79
-
// ... other Rsbuild configurations
80
64
};
81
65
```
82
66
83
-
The configuration file exports a default object that includes a `lib` array and shared Rsbuild configuration options. You can find detailed descriptions of all configs on the [Configure Overview](/config/) page.
67
+
Rslib will generate the [environments](/guide/advanced/environments) configuration of Rsbuild internally, please refer to [Configuration Debug](#configuration-debug) to view the final generated configuration.
84
68
85
-
-**[Lib Configurations](/config/lib/) (at least one object is required)**: The `lib` array contains multiple objects, each representing a set of independent configurations that will generate different outputs. Each object within the `lib` array can specify unique configurations, which is a superset of Rsbuild
86
-
configurations along with Rslib's specific configurations.
87
-
-**Shared [Rsbuild Configurations](/config/rsbuild/) (optional)**: Outside the `lib` array, there are shared Rsbuild configuration options that will be deep merged with independent Rsbuild configuration of each `lib` configuration object.
69
+
You can also refer to the [Configuration Overview](/config/) page to view the detailed introduction of all configurations.
88
70
89
-
Rslib generates corresponding Rsbuild [environments](https://rsbuild.dev/guide/advanced/environments) configurations based on the multiple build configurations of different output formats. You can view the final generated configurations through the [configuration debug](#configuration-debug) documentation.
90
-
91
-
## Configuration Usage
71
+
## Configuration File
92
72
93
73
When you use the CLI of Rslib, Rslib will automatically read the configuration file in the root directory of the current project and resolve it in the following order:
In Rslib project, you can configure Rsbuild related configurations in both `lib` configuration object and shared configuration section.
177
-
178
-
Common-used Rsbuild configurations in library development are listed at [Rsbuild Configuration](/config/rsbuild/).
156
+
Rslib allows you to use most of the Rsbuild configurations. Currently, the `environments` config is not supported because it is generated internally by Rslib.
179
157
180
-
You can also refer to the [Rsbuild Configuration](https://rsbuild.dev/config/index#config-overview) for checking the complete configuration items.
158
+
- Refer to [Rsbuild Configuration](/config/rsbuild/) for common Rsbuild configurations.
159
+
- Refer to [Rsbuild Documentation](https://rsbuild.dev/config/index#config-overview) for all Rsbuild configurations.
181
160
182
161
## Configure Rspack
183
162
@@ -195,7 +174,7 @@ DEBUG=rsbuild pnpm build
195
174
196
175
In debug mode, Rslib will write the Rsbuild / Rspack config to the dist directory, which is convenient for developers to view and debug.
197
176
198
-
Below is an example of a configuration for Rslib that builds both CJS and ESM output.
177
+
Here is an example, this is a library that sets both CJS and ESM formats:
199
178
200
179
```
201
180
Inspect config succeed, open following files to view the content:
0 commit comments