gpt4 book ai didi

node.js - nodemon 在 package.json 中执行 "prestart"脚本

转载 作者:太空宇宙 更新时间:2023-11-03 23:33:24 25 4
gpt4 key购买 nike

我想设置nodemon以在服务器重新启动时运行“prestart”脚本,原因是,我正在使用webpack并且我想在每次文件更改时构建bundle.js,我没有使用webpack-dev-server因为我不知道如何在运行现有 Node 应用程序的情况下设置它,我在node.js上获得了我的后端,对此的帮助将不胜感激。

我一直以来的工作方式是:每次对代码进行更改时运行npm start,但这太费力了。

这是 package.json 中的 scripts 对象,以便您了解发生了什么:

"scripts": {
"bundle": "webpack --config webpack.config.js",
"prestart": "npm run bundle",
"start": "node server.js"
}

最佳答案

我完成此操作的方法是使用 exec 属性创建一个 nodemon.json 文件:

 {
// ... Other conf (see an example in https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md)
"watch": [
"app" // Set your directories/files to watch
],
"exec": "npm run prestart && node server/index.js"
}

关于node.js - nodemon 在 package.json 中执行 "prestart"脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35521978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com