【问题标题】:How to run ng-serve with expressjs?如何使用 expressjs 运行 ng-serve?
【发布时间】:2018-11-08 10:45:08
【问题描述】:

我正在这样做Angular6/Express tutorial,他们使用:

"scripts": {
  "ng": "ng",
  "start": "ng build && node ./bin/www",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e"
},

为了构建 Angular 应用程序,我想通过在端口 3000 上运行的 ExpressJS 服务器来提供它。这很好用。但是当我编辑一些代码时,构建当然不会更新,因为它使用了构建命令。

是否可以将ng serve 与 ExpressJS 服务器一起使用,这样我就不必经常重启服务器?

【问题讨论】:

    标签: angular express


    【解决方案1】:

    很遗憾,没有。 ng serve 专门用于开发 Angular 应用程序。上面的start 脚本指示使用ng build 进行构建,然后运行node ./bin/www 以提供来自先前ng build 的构建内容。

    您可能想在其端口(默认 4200)上开发 Angular 应用程序并使用 ng serve 而不是使用 start 脚本。

    【讨论】:

    • 找到这个来源,medium.com/@danielkagan/… 有点做我想做的事。
    • 不错。但是文章中的方法有点扼杀了拥有代理文件或使用 express static 为后端提供 SPA 的目的。出于开发目的,不妨同时使用代理服务并启动 server.js 而无需完全进行 ng build。这就是我个人的想法。
    • 我认为这就是他所做的。 "start": "npm run build & concurrently --kill-others \"npm run serve-api\" \"npm run serve\"", "serve": "ng serve --proxy-config proxy.conf.json",
    • 但是那里的 ng 构建是多余的 ;)
    • 我想它是,但它只在开始时构建。
    猜你喜欢
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2019-01-07
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多