gpt4 book ai didi

Angular 6,在 ng build index.html 在控制台中出现错误之后

转载 作者:太空狗 更新时间:2023-10-29 17:51:03 25 4
gpt4 key购买 nike

我遇到了一个问题,请帮助我解决这个问题。问题是,当我在我的 CLI 中执行 ng build 并转到 dist 文件夹并运行 index.html 文件时,控制台会收到文件路径错误。

Failed to load resource: net::ERR_FILE_NOT_FOUND
polyfills.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
styles.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
scripts.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
vendor.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
main.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
/D:/favicon.ico:1 Failed to load resource: net::ERR_FILE_NOT_FOUND

最佳答案

它只与路径有关,只需在构建时使用 --base-href 标志,如下所示 -

ng build --prod --base-href ./

现在它会在您的 index.html 中生成类似于以下内容的行 -

<base href="./">
<!-- Note the file names here -->
<script type="text/javascript" src="runtime.30458714a8af1a2e7153.js"></script>
<script type="text/javascript" src="polyfills.db85ebdc34f3cf0f4d3f.js"></script>
<script type="text/javascript" src="scripts.e8fe6486441dc07e00c6.js"></script>
<script type="text/javascript" src="main.f9ea86a83ded92312d0f.js"></script>

就是这样!它无处不在,您只需部署生产构建,就可以开始了!

Also, please note that if you are trying to run index.html right from your files, it won't work. You'll need to place it on a http server (for example, XAMPP for local)

关于Angular 6,在 ng build index.html 在控制台中出现错误之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53985119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com