Skip to content

Commit d3b91de

Browse files
committed
better typescript playbooks. #884 #909
1 parent c420fee commit d3b91de

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

README.md

+30-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![PRs Welcome][prs-badge]][prs] [![Chat][chat-badge]][chat]
88
[![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)
1010

1111
[![Watch on GitHub][github-watch-badge]][github-watch]
1212
[![Star on GitHub][github-star-badge]][github-star]
@@ -98,9 +98,13 @@ Follow [these code examples](https://github.com/Grimones/cra-rhl/commit/4ed74af2
9898

9999
### TypeScript
100100

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.
102102
Just add `babel-loader` into your Webpack configuration, with React Hot Loader plugin.
103103

104+
There is 2 different ways to do it.
105+
106+
##### Add babel AFTER typescript.
107+
104108
```js
105109
{
106110
test: /\.tsx?$/,
@@ -117,7 +121,7 @@ Just add `babel-loader` into your Webpack configuration, with React Hot Loader p
117121
}
118122
```
119123

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.
121125

122126
```json
123127
// tsconfig.json
@@ -127,7 +131,29 @@ You **also have to modify your `tsconfig.json`**:
127131
}
128132
```
129133

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)
131157

132158
We also have a [full example running TypeScript + React Hot Loader](https://github.com/gaearon/react-hot-loader/tree/master/examples/typescript).
133159

@@ -458,8 +484,6 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
458484
<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>
459485
<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>
460486

461-
462-
463487
## License
464488

465489
MIT

0 commit comments

Comments
 (0)