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