Skip to content

Commit da20bb6

Browse files
feat: make @ui5/webcomponents-fiori peer-dependency optional (#7640)
Closes #7720 --------- Co-authored-by: Marcus Notheis <[email protected]>
1 parent 50c7e5d commit da20bb6

File tree

6 files changed

+90
-47
lines changed

6 files changed

+90
-47
lines changed

README.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,32 @@ You can find our documentation under the following links:
7474

7575
## Download and Installation
7676

77-
To consume `ui5-webcomponents-react`, you need to install the npm modules and required peer dependencies:
77+
You can install `@ui5/webcomponents-react` along with the required peer-dependencies based on the components you plan to use. **In most cases, the recommended installation is the most maintainable option.**
78+
79+
### Recommended Installation
80+
81+
Install `@ui5/webcomponents-react` along with the `@ui5/webcomponents` and `@ui5/webcomponents-fiori` peer-dependencies as dependencies in your project:
7882

7983
```sh
8084
npm install @ui5/webcomponents-react @ui5/webcomponents @ui5/webcomponents-fiori
8185
```
8286

87+
**Note:** If you import anything from another `@ui5/webcomponents-xyz` package, we recommend installing it as a dependency as well, even if it’s already included through another package.
88+
89+
### Minimal Installation
90+
91+
Since version `v2.14.0` of `@ui5/webcomponents-react`, `@ui5/webcomponents-fiori` is an optional peer-dependency. You will still need to install it if:
92+
93+
- You want to use any [component](https://sap.github.io/ui5-webcomponents/components/fiori/) from the `@ui5/webcomponents-fiori` package.
94+
- You want to use the [VariantManagement](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/inputs-variantmanagement--docs) component.
95+
- You import anything from the `@ui5/webcomponents-fiori` package.
96+
97+
**Note:** Most popular bundlers enable tree-shaking for production builds, so there’s no difference in the final bundle size between the recommended and minimal installations.
98+
99+
```sh
100+
npm install @ui5/webcomponents-react @ui5/webcomponents
101+
```
102+
83103
## End of Support for Version 1.x
84104

85105
The support for version 1.x of `ui5-webcomponents-react` has ended on **July 1, 2025**. We recommend migrating to version 2.x as soon as possible. For more information, please refer to our [Migration Guide](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/migration-guide--docs).
@@ -110,38 +130,32 @@ You can find a curated list of project templates and examples on our [Project Te
110130

111131
### Add `@ui5/webcomponents-react` to an existing app
112132

113-
First of all, you need to add the `@ui5/webcomponents-react` dependency to your project. Please also keep in mind installing the required peer dependencies:
133+
1. Install all [required dependencies](#download-and-installation)
114134

115-
```sh
116-
npm install @ui5/webcomponents @ui5/webcomponents-react @ui5/webcomponents-fiori
117-
```
135+
2. Import the `ThemeProvider` component and wrap your root component with it:
118136

119-
In order to use `@ui5/webcomponents-react` you have to wrap your application's root component into the `ThemeProvider`.<br/>
120-
You will find this component most likely in `src/index.js`:
121-
122-
```jsx
123-
import { ThemeProvider } from '@ui5/webcomponents-react';
124-
...
125-
const root = createRoot(document.getElementById("root"));
126-
root.render(
127-
<ThemeProvider>
128-
<App />
129-
</ThemeProvider>
130-
);
131-
```
137+
```tsx
138+
import { ThemeProvider } from '@ui5/webcomponents-react';
139+
...
140+
createRoot(document.getElementById('root') as HTMLElement).render(
141+
<ThemeProvider>
142+
<App />
143+
</ThemeProvider>,
144+
);
145+
```
132146

133-
Then you are ready to use `@ui5/webcomponents-react` and you can import the desired component(s) in your app:<br />
134-
For example, to use the `Button` component you need to import it:
147+
3. Use `@ui5/webcomponents-react` components in your app by importing them.
148+
For example, to use the `Button` component you need to import it:
135149

136-
```jsx
137-
import { Button } from '@ui5/webcomponents-react'; // loads ui5-button wrapped in a ui5-webcomponents-react component
138-
```
150+
```jsx
151+
import { Button } from '@ui5/webcomponents-react'; // loads ui5-button wrapped in a ui5-webcomponents-react component
152+
```
139153

140-
Then, you can use the Button in your app:
154+
4. Add the imported component to your JSX:
141155

142-
```jsx
143-
<Button onClick={() => alert('Hello World!')}>Hello world!</Button>
144-
```
156+
```jsx
157+
<Button onClick={() => alert('Hello World!')}>Hello world!</Button>
158+
```
145159

146160
### Browser Support
147161

docs/Welcome.mdx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,53 @@ In about an hour you will create a business dashboard from scratch and get famil
4646

4747
You can find a curated list of project templates and examples on our [Project Templates & Examples page](?path=/docs/project-templates-examples--docs).
4848

49-
### Add `@ui5/webcomponents-react` to an existing app
49+
### Download and Installation
5050

51-
First of all, you need to add the `@ui5/webcomponents-react` dependency to your project. Please also keep in mind installing the required peer dependencies:
51+
You can install `@ui5/webcomponents-react` along with the required peer-dependencies based on the components you plan to use. **In most cases, the recommended installation is the most maintainable option.**
52+
53+
#### Recommended Installation
54+
55+
Install `@ui5/webcomponents-react` along with the `@ui5/webcomponents` and `@ui5/webcomponents-fiori` peer-dependencies as dependencies in your project:
5256

5357
```sh
54-
npm install @ui5/webcomponents @ui5/webcomponents-react @ui5/webcomponents-fiori
58+
npm install @ui5/webcomponents-react @ui5/webcomponents @ui5/webcomponents-fiori
5559
```
5660

57-
#### Versions Table
61+
**Note:** If you import anything from another `@ui5/webcomponents-xyz` package, we recommend installing it as a dependency as well, even if it’s already included through another package.
62+
63+
#### Minimal Installation
64+
65+
Since version `v2.14.0` of `@ui5/webcomponents-react`, `@ui5/webcomponents-fiori` is an optional peer-dependency. You will still need to install it if:
66+
67+
- You want to use any [component](https://sap.github.io/ui5-webcomponents/components/fiori/) from the `@ui5/webcomponents-fiori` package.
68+
- You want to use the [VariantManagement](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/inputs-variantmanagement--docs) component.
69+
- You import anything from the `@ui5/webcomponents-fiori` package.
70+
71+
**Note:** Most popular bundlers enable tree-shaking for production builds, so there’s no difference in the final bundle size between the recommended and minimal installations.
72+
73+
```sh
74+
npm install @ui5/webcomponents-react @ui5/webcomponents
75+
```
76+
77+
### Version Alignment & Package Mapping
5878

5979
<VersionTable />
6080

61-
In order to use `@ui5/webcomponents-react` you have to wrap your application's root component into the `ThemeProvider`.<br/>
62-
You will find this component most likely in `src/index.js`:
81+
### Using UI5 Web Components for React
6382

64-
```jsx
83+
In order to use `@ui5/webcomponents-react` you have to wrap your application's root component into the `ThemeProvider` component.
84+
85+
```tsx
6586
import { ThemeProvider } from '@ui5/webcomponents-react';
6687
...
67-
const root = createRoot(document.getElementById("root"));
68-
root.render(
88+
createRoot(document.getElementById('root') as HTMLElement).render(
6989
<ThemeProvider>
7090
<App />
71-
</ThemeProvider>
91+
</ThemeProvider>,
7292
);
7393
```
7494

75-
Then you are ready to use `@ui5/webcomponents-react` and you can import the desired component(s) in your app:<br />
95+
Then you are ready to use `@ui5/webcomponents-react` and you can import the desired component(s) in your app.
7696
For example, to use the `Button` component you need to import it:
7797

7898
```jsx

packages/main/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
"@ui5/webcomponents-base": {
7575
"optional": true
7676
},
77+
"@ui5/webcomponents-fiori": {
78+
"optional": true
79+
},
7780
"@ui5/webcomponents-icons": {
7881
"optional": true
7982
}

packages/main/scripts/generateI18n.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ spawnSync('npx', ['prettier', '--write', path.resolve(SRC_I18N_PROPERTIES, 'i18n
5858
// generate Assets.js and Assets-fetch.js
5959
const jsonImports = await readdir(TARGET_I18N_JSON_IMPORTS);
6060

61-
const assets = [`import '@ui5/webcomponents/dist/Assets.js';`, `import '@ui5/webcomponents-fiori/dist/Assets.js';`];
62-
const assetsFetch = [
63-
`import '@ui5/webcomponents/dist/Assets-fetch.js';`,
64-
`import '@ui5/webcomponents-fiori/dist/Assets-fetch.js';`,
65-
];
66-
const assetsNode = [
67-
`import '@ui5/webcomponents/dist/Assets-node.js';`,
68-
`import '@ui5/webcomponents-fiori/dist/Assets-node.js';`,
69-
];
61+
function createDynamicFioriAssetsImport(suffix) {
62+
return `try {
63+
await import('@ui5/webcomponents-fiori/dist/Assets${suffix}.js');
64+
} catch {
65+
console.warn("Skipped '@ui5/webcomponents-fiori/dist/Assets${suffix}.js' import!")
66+
}`;
67+
}
68+
69+
const assets = [`import '@ui5/webcomponents/dist/Assets.js';`, createDynamicFioriAssetsImport('')];
70+
const assetsFetch = [`import '@ui5/webcomponents/dist/Assets-fetch.js';`, createDynamicFioriAssetsImport('-fetch')];
71+
const assetsNode = [`import '@ui5/webcomponents/dist/Assets-node.js';`, createDynamicFioriAssetsImport('-node')];
7072

7173
for (const file of jsonImports) {
7274
if (file.includes('-fetch')) {

packages/main/src/components/VariantManagement/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const booleanProps = {
6363
*
6464
* __Note:__ Each `VariantManagement` component can only have one default and one selected variant.
6565
*
66+
* __Note:__ You have to install `@ui5/webcomponents-fiori` to use this component.
67+
*
6668
* ### Matching header styles
6769
*
6870
* To ensure consistent header styles for different use-cases of the `VariantManagement`, we recommend setting the following styles to the `ui5-title` component:

yarn.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,6 +5004,8 @@ __metadata:
50045004
optional: true
50055005
"@ui5/webcomponents-base":
50065006
optional: true
5007+
"@ui5/webcomponents-fiori":
5008+
optional: true
50075009
"@ui5/webcomponents-icons":
50085010
optional: true
50095011
languageName: unknown

0 commit comments

Comments
 (0)