1. 安装环境搭建:http://nodejs.cn/download/下载对应的版本
2. 国内使用npm速度较慢,可以使用淘宝定制的cnpm。
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config set registry https://registry.npm.taobao.org
3. 使用create-react-app快速构建开发环境
cnpm install -g create-react-app
create-react-app blog
cd blog
4. 修改默认端口为80:
Linux:
vim package.json
{
"name": "blog",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.0"
},
"scripts": {
"start": "PORT=80 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
windows: 记事本打开package.json
{
"name": "blog",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.0"
},
"scripts": {
"start": "set PORT=80 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
5. 浏览器访问:localhost