构建后无法在本地执行Angular应用程序 [英] Not able to execute Angular application locally after build

查看:147
本文介绍了构建后无法在本地执行Angular应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular的CLI工具.当我执行

I'm toying with the CLI tools for Angular. When I execute

ng服务

ng serve

该应用程序开始运行,并且运行良好.现在,我想将其分发到万维网上,并尝试通过

the application comes to live and is working all great. Now, I'd like to distribute it to the wide web and attempted building it by

ng build --verbose

ng build --verbose

这似乎起作用了,因为我没有看到任何错误或警告.但是,当我进入创建的 dist 目录并在 index.html 上执行FF时,我到达空白页.

which seems to have worked as I see no errors nor warnings. However, as I enter the created dist directory and execute FF on index.html, I arrive at a blank page.

检查源代码,我发现其中包含了捆绑包,但是作为我的Angular应用程序入口点的标签app-root没有呈现为任何东西.包含的捆绑软件列表如下(我尝试将其尽可能保持默认和标准):

Checking the source, I see that the included bundles are there but that the tag app-root that is the entry point of my Angular application isn't rendered to anything. The list of bundles included is as follows (I try to keep it as default and standard as possible):

<body style="padding-top: 70px;">
  <app-root></app-root>
  <script type="text/javascript" src="inline.bundle.js"></script>
  <script type="text/javascript" src="polyfills.bundle.js"></script>
  <script type="text/javascript" src="scripts.bundle.js"></script>
  <script type="text/javascript" src="styles.bundle.js"></script>
  <script type="text/javascript" src="vendor.bundle.js"></script>
  <script type="text/javascript" src="main.bundle.js"></script>
</body>

我假设在 inline.bundle.js 和/或其中任何一个中提供了渲染 main.bundle.js 中的内容所需的所有魔术.包括其他捆绑包.是吗?

I'm assuming that all the magic required to render the stuff in main.bundle.js is provided in inline.bundle.js and/or any of the other bundles included. Is it so?

由于我在控制台中没有看到任何错误,因此可以通过 src 目录运行它,等等.我猜我已经忘记了一些很简单的东西,需要打开或注释掉它,或者.谷歌搜索这样一个模糊的问题会导致一堆无用的信息.

Since I see no errors in the console, serving it form the src directory works etc. I'm guessing I've forgotten something fairly simple that needs to be switched on or commented out or something. Googling such a vague question resulted in a bunch of useless info.

我该怎么办?如何更深入地解决问题?

What can I do about it? How can I troubleshoot it deeper?

推荐答案

我使用此脚本而不是index.html中的<base href="/">来打开dist目录中的文件.我不确定这是否是您的解决方案,但可能会有所帮助.

I use this script instead of <base href="/"> in index.html to open file in dist directory. I'm not sure it may be the solution for you but may help.

<script>
    document.write('<base href="' + String(document.location).replace('index.html','') + '">')
    </script>

这篇关于构建后无法在本地执行Angular应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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