3

I have an angular project with html's/CSS/component(.ts files)/service(.ts files). service methods are reading data from .json files in the assets folder(not calling backend).

I am doing a prod build which will generate html's/CSS/javascript files in dist folder.

The problem is generated index.html file is not rendering, displaying blank screen in browser without server(application server). My requirement is to make this HTML work offline.

how can I export standalone html's/CSS/javascripts to work as a offline html from angular project?

Generated dist folder structure: enter image description here

4
  • 1
    Did you look at the console? Any error? Is there any http requests fired that should not? You'll need to give us more details about this "blank page". Commented Sep 17, 2021 at 7:22
  • This is happen normally. You have to host your dist files inside a serve to view the application. In the development time we are normally using ng serve for this Commented Sep 17, 2021 at 10:04
  • @Gaël J, there is no error in the console. http request are fine(anyway these are static data from json file which is working fine). the question is in general, how to convert angular project to convert to static set of files(html/js/css/json) which works without any server. Commented Sep 22, 2021 at 4:40
  • Understood, so far you are doing it right. The output of prod build can be used in a browser without any server if the code you wrote doesn't need any server. That's why we'd need more details Commented Sep 22, 2021 at 5:51

1 Answer 1

1

You can do that using http-server package.

First install the package globally

npm install http-server -g

Then inside your project directory(in the terminal) just run

http-server dist/

And if you are using Angular 6+ or above (Working with Angular 10), You have to run

http-server dist/your-project-name

Now you can visit http://localhost:8080 to view your application

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your suggestion, we want this html/js/data to export and give it users, so that they can use it offline(without any server). is there any suggestion for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.