正文
yarn add react react-dom
npm:
npm install react react-dom --save
package.json 文件内容:
{
"name": "parcel-example-react-helloworld",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
- "license": "ISC"
+ "license": "ISC",
+ "dependencies": {
+ "react": "^16.2.0",
+ "react-dom": "^16.2.0"
+ }
}
3. 添加 Babel
新建 .babelrc 文件
touch .babelrc
输入内容:
{
"presets": ["react"]
}
添加 babel-preset-react:
yarn:
yarn add babel-preset-react -D
npm:
npm install babel-preset-react --D
此时 package.json 文件内容:
{
"name": "parcel-example-react-helloworld",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
- }