用 create-react-app 创建的项目,是使用 react-script 模块来启动项目,默认运行端口是 3000。
react-script 模块
目录: /node_modules/react-scripts/scripts/start.js
// Tools like Cloud9 rely on this.
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
const HOST = process.env.HOST || '0.0.0.0';
如 将端口修改为8008
// Tools like Cloud9 rely on this.
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 8008;
const HOST = process.env.HOST || '0.0.0.0';