UNPKG

1.24 kBMarkdownView Raw
1# babel-preset-react
2
3> Babel preset for all React plugins.
4
5This 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
18Install the CLI and this preset
19
20```sh
21npm install --save-dev babel-cli babel-preset-react
22```
23
24Make a .babelrc config file with the preset
25
26```sh
27echo '{ "presets": ["react"] }' > .babelrc
28```
29
30Create a file to run on
31
32```sh
33echo '<h1>Hello, world!</h1>' > index.js
34```
35
36View 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
57babel script.js --presets react
58```
59
60### Via Node API
61
62```javascript
63require("babel-core").transform("code", {
64 presets: ["react"]
65});
66```