配置angular cli build监视模式和nodemon监视的最佳方法是什么? [英] What is the best way to configure angular cli build watch mode and nodemon watch?

查看:78
本文介绍了配置angular cli build监视模式和nodemon监视的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi I am developing a mean app using angular 4. I have used angular cli configuration. I want to auto build the code using watch mode and also want to restart the node server when any files changed.

我使用了以下命令,但不起作用

I used the following command but not working

script: {
   "server": "ng build -w && nodemon --watch src/**/*.ts --exec ts-node ./bin/www"
}

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

I have kept the configuration in the directory bin/www file which is importing server.ts from other place.

以上命令的问题是,ng cli在启用watch的情况下构建代码,但nodemon没有启动.

The problem for above command is, ng cli is building the code with watch enabled but nodemon is not starting.

所以我尝试了以下方法.但它的建筑物只有一次,因为未启用cli的监视功能.

So i tried the following. but its building only one time as watch is not enabled for cli.

script: {
   "server": "ng build && nodemon --watch src/**/*.ts --exec ts-node ./bin/www"
}

nodemon手表在两种情况下均无法正常工作.

nodemon watch not working in either case.

推荐答案

基于上面的评论,这就是我使2台服务器正常工作并对所有更改做出响应的方式.

Based on the comments above this is how I made 2 servers working and responsive to any changes.

  • 使用angular-cli工具,前端服务器创建Angular 2应用
  • 在此应用程序(后端服务器)的根目录中
  • 创建server.js文件,Express应用程序的示例为
  • create Angular 2 app using angular-cli tool, frontend server
  • create server.js file in the root of this app, backend server, example of Express app is here
  • install package npm-run-all to start 2 servers simultaneously
  • create file server.conf.json in the root of the app with the following content
{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false
  }
}

  • 修改package.json以具有此部分
  • "scripts": {
      "client": "ng serve --proxy-config server.conf.json",
      "server": "nodemon server.js",
      "start": "npm-run-all -p client server"
    }
    

    • 运行"npm start"
    • 现在 ng服务正在观察Node中Angular和 nodemon 中的任何变化.

      Now ng serve is watching any changes in Angular and nodemon - in 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
      

      这篇关于配置angular cli build监视模式和nodemon监视的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆