Skip to content

Commit 562d099

Browse files
LilyanaOviPekskondov
authored andcommitted
docs: review of Creating UI5 Web Components Packages.md (#3318)
1 parent c3a14a3 commit 562d099

File tree

1 file changed

+50
-53
lines changed

1 file changed

+50
-53
lines changed

docs/dev/Creating UI5 Web Components Packages.md

+50-53
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Creating a custom UI5 Web Components package
1+
# Creating a Custom UI5 Web Components Package
22

33
This tutorial explains how to:
4-
- create an NPM package for your own UI5 Web Components
5-
- use UI5 Web Components' standard build tools: `@ui5/webcomponents-tools`
6-
- gain all `@ui5/webcomponents` capabilities such as HBS template support, i18n, theming, test setup, etc...
4+
- Create an NPM package for your own UI5 Web Components.
5+
- Use UI5 Web Components' standard build tools: `@ui5/webcomponents-tools`.
6+
- Gain all `@ui5/webcomponents` capabilities such as HBS template support, i18n, theming, test setup, etc.
77

88
*Note:* Whether you use `npm` or `yarn` is a matter of preference.
99

10-
## Step 1 - create an empty NPM package
10+
## Step 1. Create an empty NPM package
1111

1212
`npm init`
1313

@@ -17,7 +17,7 @@ or
1717

1818
The name that you give to your package will be used by the UI5 Web Components tools as the namespace for resource registration.
1919

20-
## Step 2 - add the UI5 Web Components packages as dependencies
20+
## Step 2. Add the UI5 Web Components packages as dependencies
2121

2222
With `npm`:
2323
- `npm i --save @ui5/webcomponents-base @ui5/webcomponents-theme-base @ui5/webcomponents-tools`
@@ -29,22 +29,22 @@ or with `yarn`:
2929
- `yarn add -D chromedriver`
3030
- (Optional) `yarn add @ui5/webcomponents-ie11`
3131

32-
These three `@ui5/` packages will serve as foundation for your own package and web components.
32+
These three `@ui5/` packages will serve as foundation for your own package and Web Components.
3333

3434
Package | Description
3535
----------------|-----------------------
36-
`@ui5/webcomponents-base` | Base classes and Framework
36+
`@ui5/webcomponents-base` | Base classes and framework
3737
`@ui5/webcomponents-theme-base` | Base theming assets
3838
`@ui5/webcomponents-tools` | Build and configuration assets
3939
`@ui5/webcomponents-ie11` | (Optional) Internet Explorer 11 polyfills and adapter code
4040

4141
*Note:* `chromedriver` is a peer dependency of `@ui5/webcomponents-tools` so that you get to choose the exact version,
42-
if necessary. This is useful if, for example, you manually update Chrome on your system and you'd prefer to not have
42+
if necessary. This is useful if, for example, you manually update Chrome on your system and you'd prefer not to have
4343
a fixed `chromedriver` version packaged with `@ui5/webcomponents-tools`.
4444

4545
*Note:* `@ui5/webcomponents-ie11` is optional and should not be installed unless you need Internet Explorer 11 support.
4646

47-
## Step 3 - run the package initialization script
47+
## Step 3. Run the package initialization script
4848

4949
Run the initialization script, optionally with parameters from the following table:
5050

@@ -61,14 +61,14 @@ to get all the default values, or:
6161

6262
`npx wc-init-ui5-package --port=8081 --tag=my-new-component`
6363

64-
to change the port and the tag of the sample web component that will be created in the empty package.
64+
to change the port and the tag of the sample Web Component that will be created in the empty package.
6565

66-
*Please note that the usage of the `ui5-` prefix is strongly discouraged, although not forbidden, for third-party components.
67-
This is due to the possibility of name clashes in the future. If you insist on using it*
66+
*Please, note that the usage of the `ui5-` prefix is strongly discouraged, although not forbidden, for third-party components.
67+
This is due to the possibility of name clashes in the future.*
6868

6969
The initialization script will set the directory structure and copy a couple of files.
7070

71-
## Step 4 - run the dev server and test the build
71+
## Step 4. Run the dev server and test the build
7272

7373
To run the dev server:
7474

@@ -82,7 +82,7 @@ and once the project is built for the first time, open in your browser:
8282

8383
`http://localhost:8080/test-resources/pages/index.html`
8484

85-
*Note:* If you chose a different `port` earlier, change `8080` to its value.
85+
*Note:* If you've chosen a different `port` earlier, change `8080` to its value.
8686

8787
You can also run the tests:
8888

@@ -107,42 +107,42 @@ That's it!
107107

108108
## Understanding the project structure
109109

110-
### package.json
110+
### `package.json`
111111

112112
The initialization script will create several NPM scripts for you in `package.json`.
113113

114114
Task | Purpose
115115
-----|-------
116-
clean | Deletes the `dist/` directory with the build output
117-
build | Production build to the `dist/` directory
118-
lint | Run a static code scan with `eslint`
119-
start | Build the project for development, run the dev server and watch for changes
120-
watch | Watch for changes only
121-
serve | Run the dev server only
122-
test | Run the dev server and execute the specs from the `test/specs/` directory
123-
create-ui5-element | Create an empty web component with the given name
116+
clean | Delete the `dist/` directory with the build output.
117+
build | Production build to the `dist/` directory.
118+
lint | Run a static code scan with `eslint`.
119+
start | Build the project for development, run the dev server and watch for changes.
120+
watch | Watch for changes only.
121+
serve | Run the dev server only.
122+
test | Run the dev server and execute the specs from the `test/specs/` directory.
123+
create-ui5-element | Create an empty Web Component with the given name.
124124

125125
### Files in the main directory
126126

127127
The initialization script will create several files in your package's main directory.
128128

129129
File | Purpose
130130
------|-------
131-
.eslintignore | Excludes the `dist/` and `test/` directories from static code scans
132-
package-scripts.js | An [nps](https://www.npmjs.com/package/nps) package scripts configuration file
133-
bundle.esm.js | Entry point for the ES6 bundle, used for development and tests. Intended for modern browsers.
134-
bundle.es5.js | Entry point for the ES5 bundle, used for development and tests. Intended for IE11 only. Delete this file if you don't need IE11 support.
131+
.eslintignore | Excludes the `dist/` and `test/` directories from static code scans.
132+
package-scripts.js | An [nps](https://www.npmjs.com/package/nps) package scripts configuration file.
133+
bundle.esm.js | Entry point for the ES6 bundle used for development and tests. Intended for modern browsers.
134+
bundle.es5.js | Entry point for the ES5 bundle used for development and tests. Intended for IE11 only. Delete this file if you don't need IE11 support.
135135

136136
You'll likely only need to change `bundle.esm.js` to import your new components there.
137137

138138
### The `config/` directory
139139

140-
The `config/` directory serves as a central place for most build and test tools' configuration assets. Normally you
140+
The `config/` directory serves as a central place for most build and test tools configuration assets. Normally, you
141141
don't need to change any files there.
142142

143143
#### Custom configuration
144144

145-
The files in the `config/` directory simply import UI5 Web Components' default configuration for all tasks: `rollup`, `wdio`, `eslint`, etc...
145+
The files in the `config/` directory simply import UI5 Web Components default configuration for all tasks: `rollup`, `wdio`, `eslint`, etc.
146146

147147
If you need to customize any configuration, simply put your own content into the respective file in `config/`.
148148

@@ -153,7 +153,7 @@ Examples:
153153
```js
154154
module.exports = require("@ui5/webcomponents-tools/components-package/eslint.js");
155155
```
156-
As you can see, this is just a proxy to UI5 Web Components' default configuration.
156+
As you can see, this is just a proxy to UI5 Web Components default configuration.
157157
Put your own content instead:
158158
```js
159159
module.exports = {
@@ -175,7 +175,7 @@ Examples:
175175
module.exports = require("@ui5/webcomponents-tools/components-package/wdio.js");
176176
```
177177

178-
Again, this is a proxy to UI5 Web Components' default configuration.
178+
Again, this is a proxy to UI5 Web Components default configuration.
179179

180180
You could just paste the content of `@ui5/webcomponents-tools/components-package/wdio.js` here and modify at will.
181181

@@ -192,22 +192,21 @@ Examples:
192192
193193
### The `src/` directory
194194
195-
This is where you'll do most of the development.
196-
Let's see the necessary files for a `my-first-component` component.
195+
This is where you'll do most of the development. Let's see the necessary files for a `my-first-component` component.
197196
198197
#### Class and template files
199198
200-
The main files describing a web component are:
199+
The main files describing a Web Component are:
201200
202201
File | Purpose
203202
------------|-------------
204-
`src/MyFirstComponent.js` | Web component class
203+
`src/MyFirstComponent.js` | Web Component class
205204
`src/MyFirstComponent.hbs` | Handlebars template
206205
207206
In order to understand how a UI5 Web Component works and what lies behind these two files, make sure you check the
208207
[Developing Web Components](./Developing%20Web%20Components.md) section of the documentation.
209208
210-
For the purposes of this tutorial however, you don't need to understand their internals, as they are automatically generated by the
209+
For the purposes of this tutorial, however, you don't need to understand their internals, as they are automatically generated by the
211210
script and are in a working state already.
212211

213212
#### Theming-related files
@@ -219,17 +218,17 @@ In addition, you can define your own CSS Vars and provide different values for t
219218

220219
File | Purpose
221220
------------|-------------
222-
`src/themes/MyFirstComponent.css` | All CSS rules for the web component, same for all themes. Will be inserted in the shadow root.
223-
`src/themes/sap_belize/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_belize` theme.
224-
`src/themes/sap_belize_hcb/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_belize_hcb` theme.
225-
`src/themes/sap_belize_hcw/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_belize_hcw` theme.
226-
`src/themes/sap_fiori_3/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3` theme.
227-
`src/themes/sap_fiori_3_dark/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3_dark` theme.
228-
`src/themes/sap_fiori_3_hcb/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3_hcb` theme.
229-
`src/themes/sap_fiori_3_hcw/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3_hcw` theme.
221+
`src/themes/MyFirstComponent.css` | All CSS rules for the Web Component, same for all themes; will be inserted in the shadow root.
222+
`src/themes/sap_belize/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_belize` theme
223+
`src/themes/sap_belize_hcb/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_belize_hcb` theme
224+
`src/themes/sap_belize_hcw/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_belize_hcw` theme
225+
`src/themes/sap_fiori_3/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3` theme
226+
`src/themes/sap_fiori_3_dark/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3_dark` theme
227+
`src/themes/sap_fiori_3_hcb/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3_hcb` theme
228+
`src/themes/sap_fiori_3_hcw/parameters-bundle.css` | Values for the component-specific CSS Vars for the `sap_fiori_3_hcw` theme
230229

231230
*Note:* It's up to you whether to put the CSS Vars directly in the `parameters-bundle.css` files for the different themes or to
232-
import them from separate `.css` files. You could have for example a `MyFirstComponent-params.css` file for each theme and
231+
import them from separate `.css` files. You could have, for example, a `MyFirstComponent-params.css` file for each theme and
233232
import it into the `parameters-bundle.css` file: `@import "MyFirstComponent-params.css";`.
234233
235234
Again, to know more about how these files work, you could have a look at the [Developing Web Components](./Developing%20Web%20Components.md#css) section of the documentation.
@@ -265,20 +264,18 @@ PLEASE_WAIT=Espere
265264
266265
File | Purpose
267266
------------|-------------
268-
`src/Assets.js` | Entry point for your package's assets
267+
`src/Assets.js` | Entry point for your package assets.
269268
270269
This module imports all base assets (such as `CLDR` and the base theme parameters), but also your own
271-
package's assets (i18n and package-specific theme parameters).
272-
Users of your package will have to import this module in their production applications in order to get additional themes support
273-
and i18n support.
270+
package assets (i18n and package-specific theme parameters). Users of your package will have to import this module in their production applications in order to get additional themes support and i18n support.
274271
275272
*Note:* For easier development and testing, `Assets.js` is also imported in the dev/test bundle `bundle.esm.js` by the initialization script.
276273
277274
### The `test/` directory
278275
279276
File | Purpose
280277
------------|-------------
281-
`test/pages/*` | Simple `.html` pages used for development and tests
278+
`test/pages/*` | Simple `.html` pages used for development and tests.
282279
`src/specs/*` | Test specs, based on [WDIO](https://www.npmjs.com/package/wdio). They use the test pages for setup.
283280
284281
You can execute all specs by running `yarn test` or `npm run test`.
@@ -305,7 +302,7 @@ import "my-ui5-webcomponents/dist/SomeOtherComponent.js";
305302
import "my-ui5-webcomponents/dist/YetAnotherComponent.js";
306303
```
307304

308-
*Note about assets:* The `Assets.js` module may import some relatively big `JSON` modules, containing CLDR data, i18n texts and theming parameters.
309-
Therefore, it is recommended to guide your package's users to bundle their apps efficiently by configuring `rollup` or `webpack`,
305+
*Note about assets:* The `Assets.js` module may import some relatively big `JSON` modules containing CLDR data, i18n texts and theming parameters.
306+
Therefore, it is recommended to guide your package users to bundle their apps efficiently by configuring `rollup` or `webpack`,
310307
depending on their choice, to not include the content of the assets `JSON` modules in their javascript bundle.
311308
See the [Efficient asset bundling](../Assets.md#bundling) section of our [Assets](../Assets.md) documentation for details.

0 commit comments

Comments
 (0)