ReactJS: Changing Default Port 3000 in create-react-app

总共有三种方法

  1. 配置全局变量
  2. 配置 package 文件
  3. 创建 .env

1)配置全局变量

1
export PORT=8000
  1. 配置 package 文件
1
2
3
4
5
6
7
8

"scripts": {
"start": “PORT=8000 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}

3.创建 .env

1
PORT=8000

参考

ReactJS: Changing Default Port 3000 in create-react-app