Skip to content

Commit 59a8220

Browse files
committed
chore: modify cli commands and add docs
1 parent dc28e08 commit 59a8220

File tree

2 files changed

+108
-3
lines changed

2 files changed

+108
-3
lines changed

packages/core/src/cli/commands.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ export function runCli(): void {
5757
});
5858

5959
inspectCommand
60-
.description('inspect the Rslib / Rsbuild / Rspack configs')
61-
.option('--env <env>', 'specify env mode', 'development')
62-
.option('--output <output>', 'specify inspect content output path', './')
60+
.description('inspect the Rsbuild / Rspack configs of Rslib projects')
61+
.option(
62+
'--output <output>',
63+
'specify inspect content output path',
64+
'.rsbuild',
65+
)
6366
.option('--verbose', 'show full function definitions in output')
6467
.action(async (options: InspectOptions) => {
6568
try {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,103 @@
11
# CLI
2+
3+
Rslib comes with a lightweight CLI that includes commands such as build and inspect.
4+
5+
## rslib -h
6+
7+
To view all available CLI commands, run the following command in the project directory:
8+
9+
```bash
10+
npx rslib -h
11+
```
12+
13+
The output is shown below:
14+
15+
```text
16+
Usage: rslib <command> [options]
17+
18+
Options:
19+
-V, --version output the version number
20+
-h, --help display help for command
21+
22+
Commands:
23+
build [options] build the library for production
24+
inspect [options] inspect the Rsbuild / Rspack configs of Rslib projects
25+
help [command] display help for command
26+
```
27+
28+
## rslib build
29+
30+
The `rslib build` command will build the outputs for production in the `dist/` directory by default.
31+
32+
```text
33+
Usage: rslib build [options]
34+
35+
build the library for production
36+
37+
Options:
38+
-c --config <config> specify the configuration file, can be a relative or absolute path
39+
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
40+
-w --watch turn on watch mode, watch for changes and rebuild
41+
-h, --help display help for command
42+
```
43+
44+
:::tip
45+
46+
You can use `rslib build --watch` to turn on watch mode for watching for changes and rebuild.
47+
:::
48+
49+
## rslib inspect
50+
51+
The `rslib inspect` command is used to view the Rsbuild config and Rspack config of the Rslib project.
52+
53+
```text
54+
Usage: rslib inspect [options]
55+
56+
inspect the Rsbuild / Rspack configs of Rslib projects
57+
58+
Options:
59+
-c --config <config> specify the configuration file, can be a relative or absolute path
60+
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
61+
--output <output> specify inspect content output path (default: ".rsbuild")
62+
--verbose show full function definitions in output
63+
-h, --help display help for command
64+
```
65+
66+
When you run the command `npx rslib inspect` in the project root directory, the following files will be generated in the `dist/.rsbuild` directory of the project:
67+
68+
- `rsbuild.config.mjs`: Represents the Rsbuild configuration used during the build.
69+
- `rspack.config.web.mjs`: Represents the Rspack configuration used during the build.
70+
71+
```text
72+
➜ npx rslib inspect
73+
74+
success Inspect config succeed, open following files to view the content:
75+
76+
- Rsbuild Config: /project/dist/.rsbuild/rsbuild.config.mjs
77+
- Rspack Config (esm): /project/dist/.rsbuild/rspack.config.esm.mjs
78+
```
79+
80+
### Verbose content
81+
82+
By default, the inspect command omits the content of functions in the configuration object. You can add the `--verbose` option to output the complete content of functions:
83+
84+
```bash
85+
rslib inspect --verbose
86+
```
87+
88+
### Multiple output formats
89+
90+
If the current project has multiple output formats, such as ESM artifact and CJS artifact simultaneously, multiple Rspack configuration files will be generated in the `dist/.rsbuild` directory.
91+
92+
```text
93+
➜ npx rslib inspect
94+
95+
Inspect config succeed, open following files to view the content:
96+
97+
success Inspect config succeed, open following files to view the content:
98+
99+
- Rsbuild Config (esm): /project/dist/.rsbuild/rsbuild.config.esm.mjs
100+
- Rsbuild Config (cjs): /project/dist/.rsbuild/rsbuild.config.cjs.mjs
101+
- Rspack Config (esm): /project/dist/.rsbuild/rspack.config.esm.mjs
102+
- Rspack Config (cjs): /project/dist/.rsbuild/rspack.config.cjs.mjs
103+
```

0 commit comments

Comments
 (0)