Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 6b3a3be

Browse files
committed
Document recreating process properly
1 parent 341f28a commit 6b3a3be

File tree

1 file changed

+77
-16
lines changed

1 file changed

+77
-16
lines changed

README.md

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,100 @@ Find information on how to perform common tasks in [this guide](https://github.c
1818

1919
## Recreating this project from scratch
2020

21-
Execute the following commands:
22-
``` bash
21+
### Initialize using Create React App
22+
23+
```sh
2324
$ yarn global add create-react-app
2425

2526
$ create-react-app hello-react
2627
$ cd hello-react
2728

2829
$ yarn install
30+
```
31+
32+
### Upgrade to latest react-scripts
33+
34+
This is needed to get Babel 7 and compile Vaadin components properly.
35+
36+
```sh
37+
$ yarn upgrade react-scripts@next
38+
```
39+
40+
Note: Vaadin components support modern browsers and IE11, so the `browserslist` section
41+
in `package.json`, which is added when upgrading, should be updated to look like this:
42+
43+
```js
44+
"browserslist": [
45+
"last 2 versions",
46+
"ie 11"
47+
]
48+
```
49+
50+
### Install dependencies
2951

30-
$ yarn add @polymer/polymer
52+
```sh
3153
$ yarn add @vaadin/vaadin-button
3254
$ yarn add @vaadin/vaadin-text-field
3355
$ yarn add @webcomponents/webcomponentsjs
3456
```
3557

36-
Open `src/index.js`.
58+
### Add Web Components polyfill
59+
60+
1. Install the utility to copy polyfills:
61+
62+
```sh
63+
$ yarn add vendor-copy
64+
```
65+
66+
2. Update `scripts` section in `package.json` and add the line:
67+
68+
```js
69+
"postinstall": "vendor-copy"
70+
```
71+
72+
3. Add the following section to `package.json`:
73+
74+
```js
75+
"vendorCopy": [
76+
{
77+
"from": "node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js",
78+
"to": "public/vendor/custom-elements-es5-adapter.js"
79+
},
80+
{
81+
"from": "node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js",
82+
"to": "public/vendor/webcomponents-bundle.js"
83+
}
84+
],
85+
```
86+
87+
4. Open `public/index.html` and add the following lines:
88+
```html
89+
<script src="%PUBLIC_URL%/vendor/webcomponents-bundle.js"></script>
90+
<script>if (!window.customElements) { document.write('<!--'); }</script>
91+
<script src="%PUBLIC_URL%/vendor/custom-elements-es5-adapter.js"></script>
92+
<!--! DO NOT REMOVE THIS COMMENT, WE NEED ITS CLOSING MARKER -->
93+
```
3794

38-
In the `import` section before the app importing, add:
95+
5. Make sure the scripts are copied:
3996

40-
``` typescript
41-
import '@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce.js';
97+
```sh
98+
$ yarn run postinstall
4299
```
43100

44-
Open `src/App.js`.
101+
### Making Vaadin components work
102+
103+
Open `src/App.js` and do the following modifications.
45104

46-
In the `import` section, add:
105+
1. Import Vaadin components:
47106

48-
``` typescript
107+
```js
49108
import '@vaadin/vaadin-button/vaadin-button.js';
50109
import '@vaadin/vaadin-text-field/vaadin-text-field.js';
51110
```
52111

53-
Define a constructor with a simple property:
112+
2. Define a constructor for the App component:
54113

55-
```javascript
114+
```js
56115
constructor(props) {
57116
super(props);
58117
this.state = {greeting: "React App"};
@@ -61,22 +120,24 @@ constructor(props) {
61120
}
62121
```
63122

64-
Replace all the HTML in the `return` of `render` method with:
123+
3. Update the `render` method of the App component to return the HTML:
65124

66125
```html
67-
<div>
126+
<div className="App">
68127
<vaadin-text-field ref={this.textField} placeholder="Type Something"></vaadin-text-field>
69128
<vaadin-button onClick={this.clicked}>Click Me!</vaadin-button>
70129
<h2>Hello {this.state.greeting}!</h2>
71130
</div>
72131
```
73132

74-
Define the click event
133+
4. Define the click event handler
75134

76-
```javascript
135+
```js
77136
clicked() {
78137
this.setState({greeting: this.textField.current.value})
79138
}
80139
```
81140

141+
### Starting the application
142+
82143
Run the app with `yarn start`

0 commit comments

Comments
 (0)