Angular 构建 index.html 不工作

Angular build index.html not working

我已经构建了 angular 项目并获得了 dist folder.when 我正在尝试在 browser.I 中打开 index.html 我收到以下错误,如失败加载找不到 inline.bundle.js 、polyfil.bundle.js 和许多文件的资源和文件。 尽管此文件已添加到脚本标签中并且我没有更改此文件的路径,但如果我 运行 来自实时服务器,它仍然不会 working.But 它正在工作。 解释为什么没有服务器它不能工作? 为什么它不加载 inline.bundle.js,polyfill.bundle.js 是 js 文件?

找不到您的文件,因为基础 URL 已更改。

您可以通过在 index.html 中使用 <base href="./"> 来解决这个问题。

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

您也可以使用ng build --base-href ./命令,这样就不需要修改HTML文件了。

根据 Mozilla 的说法:

The HTML <base> element specifies the base URL to use for 
all relative URLs in a document. There can be only one <base> element in a document.

这意味着所有编译的资源都被引用到系统的根目录中。例如,样式和图像与 index.html 在同一文件夹中。使基础 url <base href="/"><base href="foldername of the index.html"> 使其成为对当前文件夹的引用。