|
1 | 1 | # 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