最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular build index.html not working - Stack Overflow

programmeradmin2浏览0评论

I have taken the build of angular project and got dist folder.when i am trying to open the index.html in browser.I am getting the following error like failed to load resources and file not found for inline.bundle.js ,polyfil.bundle.js and many files. Though this files added in the script tag and i didnt change the path of this file still not working.But if i run this from live server it is working. Explain why it is not working without server? Why it is not loading the inline.bundle.js,polyfill.bundle.js which are js file?

I have taken the build of angular project and got dist folder.when i am trying to open the index.html in browser.I am getting the following error like failed to load resources and file not found for inline.bundle.js ,polyfil.bundle.js and many files. Though this files added in the script tag and i didnt change the path of this file still not working.But if i run this from live server it is working. Explain why it is not working without server? Why it is not loading the inline.bundle.js,polyfill.bundle.js which are js file?

Share Improve this question edited Mar 15, 2018 at 16:25 David Walschots 12.6k5 gold badges38 silver badges59 bronze badges asked Mar 7, 2018 at 9:54 John WillsonJohn Willson 4551 gold badge3 silver badges14 bronze badges 1
  • You have to open the page using localhost:4200, it is said when you run ng start. – Akxe Commented Jan 11, 2019 at 13:08
Add a comment  | 

3 Answers 3

Reset to default 13

Your files are not found because base URL changed.

You can workaround this one by using <base href="./"> in your index.html.

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

You can also use the ng build --base-href ./ command, so that modifying the HTML file is not necessary.

According to 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.

This means all the compiled resources are being referenced in relation to the root of the system. for instance the style and the images are in the same folder as the index.html. making the base url <base href="/"> or <base href="foldername of the index.html">makes it to reference to the current folder.

发布评论

评论列表(0)

  1. 暂无评论