Skip to content

Commit be4ac92

Browse files
committed
docs
1 parent e46f8dc commit be4ac92

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

docs/knowledge-base/FAQ.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,45 @@ import { Button } from '@ui5/webcomponents-react/Button';
117117
// ...
118118
```
119119

120+
## Why Use Direct Imports via Package Export Maps
121+
122+
Since [v2.14.0](https://github.com/UI5/webcomponents-react/releases/tag/v2.14.0), `ui5-webcomponents-react` supports **export maps** through the `exports` field in `package.json` ([documentation](https://nodejs.org/api/packages.html#exports)).
123+
124+
Export maps allow you to import components directly from their package entry points instead of relying on deep file paths or the package root (barrel) files.
125+
While most bundlers perform tree-shaking in production builds, so only the code you actually use is included, tree-shaking is often limited or disabled in development. If you import from the package root (a “barrel file”), all components and utilities exported from that root are included in the bundle, even those you don’t use.
126+
127+
```ts
128+
// Root import (less optimal without tree-shaking)
129+
import { Button, AnalyticalTable } from "@ui5/webcomponents-react";
130+
131+
// Direct import (recommended)
132+
import { Button } from "@ui5/webcomponents-react/Button";
133+
import { AnalyticalTable } from "@ui5/webcomponents-react/AnalyticalTable";
134+
```
135+
136+
### Codemod
137+
138+
To migrate from root imports to direct imports, you can use the `exports-map` codemod from the [cli](https://github.com/UI5/webcomponents-react/blob/main/packages/cli/README.md) package.
139+
140+
<MessageStrip
141+
hideCloseButton
142+
design="Critical"
143+
children={
144+
<>
145+
The codemod is a best-effort attempt to help you migrate to direct imports. Please review the generated code thoroughly!
146+
<br />
147+
<strong>
148+
Applying the codemod might break your code formatting, so please don't forget to run prettier and/or eslint
149+
after you've applied the codemod!
150+
</strong>
151+
</>
152+
}
153+
/>
154+
155+
```shell
156+
npx @ui5/webcomponents-react-cli codemod --transform export-maps \
157+
--src ./path/to/src \
158+
--typescript # only if you use TypeScript in your project, omit if you use JavaScript
159+
```
160+
120161
<Footer />

packages/cli/README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @ui5/webcomponents-react-cli
22

3-
Wrapper generation and code-mod for ui5-webcomponents-react.
3+
Wrapper generation and code-mod for ui5/webcomponents-react.
44

55
## Usage
66

@@ -12,19 +12,30 @@ npm install @ui5/webcomponents-react-cli
1212

1313
### Documentation
1414

15-
You can find an interactive documentation in our [Storybook](https://sap.github.io/ui5-webcomponents-react/).
15+
You can find an interactive documentation in our [Storybook](https://ui5.github.io/webcomponents-react/).
1616

1717
- [Wrapper generation](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/knowledge-base-bring-your-own-web-components--docs)
18-
- [Code-mod](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/migration-guide--docs#codemod)
19-
- ~~[Patch compatibility table](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#experimental-patch-script)~~ (deprecated in favor of [compatibility package scoping](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#using-the-compat-v1-table-together-with-the-v2-table-in-one-application))
18+
- Code-mods:
19+
- [v2](https://ui5.github.io/webcomponents-react/v2/?path=/docs/migration-guide--docs#codemod): Migrate your codebase from v1 to v2
20+
```shell
21+
npx @ui5/webcomponents-react-cli codemod --transform v2 \
22+
--src ./path/to/src \
23+
--typescript # only if you use TypeScript in your project, omit if you use JavaScript
24+
```
25+
- [export-maps](https://ui5.github.io/webcomponents-react/v2/?path=/docs/knowledge-base-faq--docs#why-use-direct-imports-via-package-export-maps): Migrate your codebase from root imports to direct imports using exports maps
26+
```shell
27+
npx @ui5/webcomponents-react-cli codemod --transform export-maps \
28+
--src ./path/to/src \
29+
--typescript # only if you use TypeScript in your project, omit if you use JavaScript
30+
```
2031

2132
## Contribute
2233

23-
Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents-react/blob/main/CONTRIBUTING.md).
34+
Please check our [Contribution Guidelines](https://github.com/UI5/webcomponents-react/blob/main/CONTRIBUTING.md).
2435

2536
## License
2637

27-
Please see our [LICENSE](https://github.com/SAP/ui5-webcomponents-react/blob/main/LICENSE) for copyright and license information.
38+
Please see our [LICENSE](https://github.com/UI5/webcomponents-react/blob/main/LICENSE) for copyright and license information.
2839
Detailed information including third-party components and their licensing/copyright information is available via the [REUSE tool](https://api.reuse.software/info/github.com/UI5/webcomponents-react).
2940

3041
<!-- Use the force -->

0 commit comments

Comments
 (0)