angular - 如何让 angular-cli 实时重新加载与我的网络服务器一起工作

标签 angular vagrant angular-cli

我需要弄清楚如何使用我的本地网络服务器进行实时重新加载。我正在使用 vagrant 在 http://admin.myproject.local 托管我的项目并使用 angular-cli 构建我的应用程序。

当使用 npm start 时,我可以在 http://localhost:4200 上实时查看我的更改但在进行构建之前,我的 admin.myproject.local 没有任何变化。我查看了 angular-cli 文档并认为代理将是解决方案。我创建了一个 proxy.conf.json 文件并添加了以下代码:

{
  "/admin": {
    "target": "http://admin.myproject.local",
    "secure": "false"
  }
}

但这似乎没有帮助。如果我尝试 http://localhost:4200/admin我收到 404。

当通过我的 .local url 访问该站点时,有人可以指出正确的方向让实时重新加载工作吗?

最佳答案

您可以创建另一个 HTML 文件(或使用您现有的服务器索引文件)并将您的脚本标记指向生成的 js 文件。例如..

<!doctype html>
<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width" />
  <base href="/"> 
</head>
<body>
    <my-app></my-app>
    <script src="http://localhost:4200/inline.js"></script>
    <script src="http://localhost:4200/scripts.bundle.js"></script>
    <script src="http://localhost:4200/main.bundle.js"></script>
</body>
</html>

这适用于开发。对于生产,在运行 ng build -prod 后包含 dist 目录中的脚本文件。

关于angular - 如何让 angular-cli 实时重新加载与我的网络服务器一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39838697/

相关文章:

php - 访问 PHP 错误日志 - Puphpet 设置的 Vagrant CentOS VM

angular - "RxJS could not find any global context"

Angular-cli、PrimeNG 和 angular-cli

具有不同 "profiles"的 Angular ng build

Javascript window.print() 方法只工作一次

angular - 使用 typescript 编写 e2e 测试(Protractor、Jasmine)

ubuntu - archive.ubuntu.com 稀有文件丢失,解决方法?

vagrant - 有没有办法在 Vagrant 中取消同步子文件夹?

javascript - 绘制自定义形状和弯曲矩形

java - PrimeNG tabMenu 单击事件对于禁用的选项卡禁用