6
6
7
7
[ ![ PRs Welcome] [ prs-badge ]] [ prs ] [ ![ Chat] [ chat-badge ]] [ chat ]
8
8
[ ![ Backers on Open Collective] [ oc-backer-badge ]] ( #backers )
9
- [ ![ Sponsors on Open Collective] [ oc-sponsor-badge ]] ( #sponsors )
9
+ [ ![ Sponsors on Open Collective] [ oc-sponsor-badge ]] ( #sponsors )
10
10
11
11
[ ![ Watch on GitHub] [ github-watch-badge ]] [ github-watch ]
12
12
[ ![ Star on GitHub] [ github-star-badge ]] [ github-star ]
@@ -98,9 +98,13 @@ Follow [these code examples](https://github.com/Grimones/cra-rhl/commit/4ed74af2
98
98
99
99
### TypeScript
100
100
101
- When using TypeScript, Babel is not required, but React Hot Loader will not work without it.
101
+ When using TypeScript, Babel is not required, but React Hot Loader will not work (properly) without it.
102
102
Just add ` babel-loader ` into your Webpack configuration, with React Hot Loader plugin.
103
103
104
+ There is 2 different ways to do it.
105
+
106
+ ##### Add babel AFTER typescript.
107
+
104
108
``` js
105
109
{
106
110
test: / \. tsx? $ / ,
@@ -117,7 +121,7 @@ Just add `babel-loader` into your Webpack configuration, with React Hot Loader p
117
121
}
118
122
```
119
123
120
- You ** also have to modify your ` tsconfig.json ` ** :
124
+ In this case you have to modify your ` tsconfig.json ` , and compile to ES6 mode, as long React-Hot-Loader babel plugin could not understand ES5 code.
121
125
122
126
``` json
123
127
// tsconfig.json
@@ -127,7 +131,29 @@ You **also have to modify your `tsconfig.json`**:
127
131
}
128
132
```
129
133
130
- Yet again - module = es6 ** will not work** .
134
+ ##### Add babel BEFORE typescript (preferred)
135
+
136
+ ``` js
137
+ {
138
+ test: / \. tsx? $ / ,
139
+ use: [
140
+ ' ts-loader' , // (or awesome-typescript-loader)
141
+ {
142
+ loader: ' babel-loader' ,
143
+ options: {
144
+ plugins: [
145
+ ' @babel/plugin-syntax-typescript' ,
146
+ ' @babel/plugin-syntax-decorators' ,
147
+ ' @babel/plugin-syntax-jsx' ,
148
+ ' react-hot-loader/babel' ,
149
+ ],
150
+ },
151
+ }
152
+ ],
153
+ }
154
+ ```
155
+
156
+ In this case you can compile to ES5. More about [ typescript and react-hot-loader] ( https://github.com/gaearon/react-hot-loader/issues/884 )
131
157
132
158
We also have a [ full example running TypeScript + React Hot Loader] ( https://github.com/gaearon/react-hot-loader/tree/master/examples/typescript ) .
133
159
@@ -458,8 +484,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
458
484
<a href =" https://opencollective.com/react-hot-loader/sponsor/8/website " target =" _blank " ><img src =" https://opencollective.com/react-hot-loader/sponsor/8/avatar.svg " ></a >
459
485
<a href =" https://opencollective.com/react-hot-loader/sponsor/9/website " target =" _blank " ><img src =" https://opencollective.com/react-hot-loader/sponsor/9/avatar.svg " ></a >
460
486
461
-
462
-
463
487
## License
464
488
465
489
MIT
0 commit comments