【问题标题】:npm start in React在 React 中启动 npm
【发布时间】:2020-04-03 03:45:22
【问题描述】:

我怎样才能通过键入 npm start 来启动这两项?

"scripts"{
    "server": "json-server --watch appointmentList.json",
    "start": "react-scripts start",
}

我一直在做的是在不同的终端运行它们中的每一个

【问题讨论】:

标签: reactjs json-server


【解决方案1】:

您可以安装concurrently 以并行运行脚本,如下所示:

{
  "dev": "concurrently \"npm run server\" \"npm start\""
}

【讨论】:

  • 没问题。如果你能接受它作为后代的答案,我会很高兴。
【解决方案2】:

简而言之,您可以将所需的命令附加到start 脚本中:

"scripts": { 
    "server": "json-server --watch appointmentList.json", 
    "start": "json-server --watch appointmentList.json && react-scripts start"
}

并使用$npm run start$npm start 调用它

【讨论】:

    【解决方案3】:

    你可以像这样使用'&&':

    {
        "server": "json-server --watch appointmentList.json", 
        "start": "npm run server && react-scripts start"
    }
    

    【讨论】:

    • 我以前试过这个,但它不起作用。我的服务器服务器运行在 3000,我的反应应用程序运行在 3001。所以我在不同的终端上运行
    猜你喜欢
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 2017-05-28
    • 2022-08-11
    相关资源
    最近更新 更多