我的项目是基于创建-反应-应用程序。NPM启动或yarn启动默认将在端口3000上运行应用程序,在package.json中没有指定端口的选项。

在这种情况下,如何指定自己选择的端口?我想同时运行这个项目的两个(用于测试),一个在端口3005,另一个是3006


当前回答

试试这个:

npm start port=30022

其他回答

只需在webpack.config.js中更新一点:

devServer: {
    historyApiFallback: true,
    contentBase: './',
    port: 3000 // <--- Add this line and choose your own port number
}

然后再次运行NPM start。

只需运行下面的命令

PORT=3001 npm start

试试这个:

npm start port=30022

为什么不干脆

PORT=3030 npm run start

可以在包中指定端口。通过定义端口号:

"scripts": {
"start": "PORT=3006 react-scripts start"}

或 在终端运行脚本时可以指定端口:

PORT=3003 npm start