配置角度cli构建监视模式和nodemon监视的最佳方法是什么?

Deb*_*nda 2 express nodemon mean-stack angular-cli angular

嗨,我正在开发一个使用角度4的平均应用程序.我使用了角度cli配置.我想使用监视模式自动构建代码,并且还希望在任何文件更改时重新启动节点服务器.

我使用了以下命令但没有工作

script: {
   "server": "ng build -w && nodemon --watch src/**/*.ts --exec ts-node ./bin/www"
}
Run Code Online (Sandbox Code Playgroud)

我已将配置保存在从其他位置bin/www导入的目录文件中server.ts.

上面命令的问题是,ng cli正在构建启用了watch的代码,但nodemon没有启动.

所以我尝试了以下内容.但它的建筑只有一次作为手表没有启用cli.

script: {
   "server": "ng build && nodemon --watch src/**/*.ts --exec ts-node ./bin/www"
}
Run Code Online (Sandbox Code Playgroud)

在任何一种情况下,nodemon都无法工作.

Ano*_*ous 6

基于上面的评论,这就是我使2台服务器工作并响应任何变化的方式.

  • 使用angular-cli工具,前端服务器创建Angular 2应用程序
  • 在这个应用程序的根目录中创建server.js文件,后端服务器,Express应用程序的示例就在这里
  • 安装包npm-run-all同时启动2台服务器
  • 使用以下内容在应用程序的根目录中创建文件server.conf.json
{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 修改package.json以获得此部分
"scripts": {
  "client": "ng serve --proxy-config server.conf.json",
  "server": "nodemon server.js",
  "start": "npm-run-all -p client server"
}
Run Code Online (Sandbox Code Playgroud)
  • 运行"npm start"

现在ng服务正在观察Angular和nodemon中的任何变化- 在Node中.

localhost:4200                  // ng serve => angular
localhost:4200/page             // ng serve => angular
localhost:4200/another/page     // ng serve => angular
localhost:4200/api              // ng serve => node
localhost:4200/api/users        // ng serve => node
localhost:3000/api              // node
localhost:3000/api/users        // node
Run Code Online (Sandbox Code Playgroud)