简体   繁体   English

nodemon在package.json中执行“ prestart”脚本

[英]nodemon to exec “prestart” script at package.json

I want to setup nodemon to run the "prestart" script when server restarts, the reason, I'm using webpack and I want to build bundle.js every time a file changes, I'm not using webpack-dev-server cause I don't know how to set it up with an existing node app running, I got my backend on node.js , help on that will be appreciated. 我想设置nodemon在服务器重新启动时运行“ prestart”脚本,原因是,我正在使用webpack,并且每次文件更改时都希望构建bundle.js ,因此我没有使用webpack-dev-server ,这是因为不知道如何在现有的节点应用程序运行的情况下进行设置,我将后端安装在node.js上,我们将为您提供帮助。

The way I've been working is: run npm start every time I make a change on the code, but that too much effort. 我一直在工作的方式是:每当我对代码进行更改时,都要运行npm start ,但是这样做太费力了。

Here's the scripts object at package.json so that you have an idea of what's going on: 这是package.json中scripts对象,以便您了解发生了什么:

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

The way I've accomplished to do that is by creating a nodemon.json file with the exec property: 我完成此操作的方法是通过使用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"
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM