-
-
Notifications
You must be signed in to change notification settings - Fork 54
feat: support lib.id #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: support lib.id #436
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,5 +10,6 @@ | |
| "footer", | ||
| "dts", | ||
| "shims", | ||
| "id", | ||
| "umd-name" | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # lib.id | ||
|
|
||
| - **Type:** `string` | ||
| - **Default:** `undefined` | ||
|
|
||
| Specify the library ID. The ID identifies the library and is useful when using the `--lib` flag to build specific libraries with a meaningful `id` in the CLI. | ||
|
|
||
| :::tip | ||
|
|
||
| Rslib uses Rsbuild's [environments](https://rsbuild.dev/guide/advanced/environments) feature to build multiple libraries in a single project under the hood. `lib.id` will be used as the key for the generated Rsbuild environment. | ||
|
|
||
| ::: | ||
|
|
||
| ## Default Value | ||
|
|
||
| By default, Rslib automatically generates an ID for each library in the format `${format}${index}`. Here, `format` refers to the value specified in the current lib's [format](/config/lib/format), and `index` indicates the order of the library within all libraries of the same format. If there is only one library with the current format, the `index` will be empty. Otherwise, it will start from `0` and increment. | ||
|
|
||
| For example, the libraries in the `esm` format will start from `esm0`, followed by `esm1`, `esm2`, and so on. In contrast, `cjs` and `umd` formats do not include the `index` part since there is only one library for each format. | ||
|
|
||
| ```ts title="rslib.config.ts" | ||
| export default { | ||
| lib: [ | ||
| { format: 'esm' }, // id is `esm0` | ||
| { format: 'cjs' }, // id is `cjs` | ||
| { format: 'esm' }, // id is `esm1` | ||
| { format: 'umd' }, // id is `umd` | ||
| { format: 'esm' }, // id is `esm2` | ||
| ], | ||
| }; | ||
| ``` | ||
|
|
||
| ## Customize ID | ||
|
|
||
| You can also specify a readable or meaningful ID of the library by setting the `id` field in the library configuration. The user-specified ID will take priority, while the rest will be used together to generate the default ID. | ||
|
|
||
| For example, `my-lib-a`, `my-lib-b`, and `my-lib-c` will be the IDs of the specified libraries, while the rest will be used to generate and apply the default ID. | ||
|
|
||
| {/* prettier-ignore-start */} | ||
| ```ts title="rslib.config.ts" | ||
| export default { | ||
| lib: [ | ||
| { format: 'esm', id: 'my-lib-a' }, // ID is `my-lib-a` | ||
| { format: 'cjs', id: 'my-lib-b' }, // ID is `my-lib-b` | ||
| { format: 'esm' }, // ID is `esm0` | ||
| { format: 'umd', id: 'my-lib-c' }, // ID is `my-lib-c` | ||
| { format: 'esm' }, // ID is `esm1` | ||
| ], | ||
| }; | ||
| ``` | ||
| {/* prettier-ignore-end */} | ||
|
|
||
| Then you could only build `my-lib-a` and `my-lib-b` by running the following command: | ||
|
|
||
| ```bash | ||
| npx rslib build --lib my-lib-a --lib my-lib-b | ||
| ``` | ||
|
|
||
| :::note | ||
| The id of each library must be unique, otherwise it will cause an error. | ||
| ::: |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.