首页 > 解决方案 > 是否可以使用 npm pre hooks 启动开发服务器?

问题描述

我目前有这样的东西,它同时运行我的开发服务器和我的 React 应用程序。

"scripts": {
    "dev": "run-p yarn proxy:start react-scripts start",
    "proxy:start": "nodemon test-proxy.js"
},

我希望做这样的事情:

"scripts": {
    "predev": "nodemon test-proxy.js",
    "dev": "react-scripts start"
},

但是由于nodemon永远不会退出,它会一直监视文件,直到您自己退出进程,所以dev脚本永远不会被触发。

是否可以运行predev,让它在后台运行(继续运行nodemon以观察文件更改,最好继续记录任何 I/O 事件)并运行我的 React 启动脚本?

标签: node.jsreactjsnpmyarnpkgnpm-scripts

解决方案


推荐阅读