1
|
# babel-preset-react
|
2
|
|
3
|
> Babel preset for all React plugins.
|
4
|
|
5
|
This preset includes the following plugins/presets:
|
6
|
|
7
|
- [preset-flow](https://babeljs.io/docs/plugins/preset-flow/)
|
8
|
- [syntax-jsx](https://babeljs.io/docs/plugins/syntax-jsx/)
|
9
|
- [transform-react-jsx](https://babeljs.io/docs/plugins/transform-react-jsx/)
|
10
|
- [transform-react-display-name](https://babeljs.io/docs/plugins/transform-react-display-name/)
|
11
|
|
12
|
## Install
|
13
|
|
14
|
> You can also check out the React [Getting Started page](https://facebook.github.io/react/docs/hello-world.html)
|
15
|
|
16
|
> For more info, check out the setup page on the [cli](/docs/setup/) and the [usage](/docs/usage/cli/) docs.
|
17
|
|
18
|
Install the CLI and this preset
|
19
|
|
20
|
```sh
|
21
|
npm install --save-dev babel-cli babel-preset-react
|
22
|
```
|
23
|
|
24
|
Make a .babelrc config file with the preset
|
25
|
|
26
|
```sh
|
27
|
echo '{ "presets": ["react"] }' > .babelrc
|
28
|
```
|
29
|
|
30
|
Create a file to run on
|
31
|
|
32
|
```sh
|
33
|
echo '<h1>Hello, world!</h1>' > index.js
|
34
|
```
|
35
|
|
36
|
View the output
|
37
|
|
38
|
```sh
|
39
|
./node_modules/.bin/babel index.js
|
40
|
```
|
41
|
|
42
|
## Usage
|
43
|
|
44
|
### Via `.babelrc` (Recommended)
|
45
|
|
46
|
**.babelrc**
|
47
|
|
48
|
```json
|
49
|
{
|
50
|
"presets": ["react"]
|
51
|
}
|
52
|
```
|
53
|
|
54
|
### Via CLI
|
55
|
|
56
|
```sh
|
57
|
babel script.js --presets react
|
58
|
```
|
59
|
|
60
|
### Via Node API
|
61
|
|
62
|
```javascript
|
63
|
require("babel-core").transform("code", {
|
64
|
presets: ["react"]
|
65
|
});
|
66
|
```
|