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