serve -s build 指定端口号

rma*_*iar 15 reactjs digital-ocean create-react-app yarnpkg

我正在尝试从 DigitalOcean droplet 提供 react-app 的构建文件夹。

After I run yarn build, I get told by the script to run

yarn global add serve serve -s build

However, when I run serve -s build, It say's it's running on http://localhost:5000. I would like it run on localhost:3000 instead, as I have another server running on port 5000. How can i specify the port number such that serve -s build runs on port 3000?

小智 26

通过打字serve --help,我发现

-l, --listen listen_uri            
Specify a URI endpoint on which to listen

For TCP ports on hostname "localhost":

$ serve -l 1234
Run Code Online (Sandbox Code Playgroud)

在你的情况下,你可以使用

serve -l 3000 -s build
Run Code Online (Sandbox Code Playgroud)

指定您要在端口 3000 上为应用程序提供服务