11 Angular in production
This chapter covers
- How to properly build Angular for production environments
- Ways to architect your application for best practices
- Inspecting your final bundle to determine how dependencies impact your app
- Deployment options and a sample Dockerfile
So, you’ve built your application—now what? That’s a loaded question, but we’ll try to unpack it in this chapter. You could do or focus on a lot of things, but not everything is necessary in all projects. There are many general web development things you can do, such as enabling gzip on your server, and there are things specific to Angular, such as ensuring you run the build using Ahead-of-Time compilation.
The way we’ve been developing our application by running ng
serve
is perfectly acceptable for development but unacceptable for production. The dev server isn’t designed to handle real web traffic, can expose vulnerabilities, and can easily crash without warning. You’ll want to use a hardened web server for hosting your application.
You may be writing applications for customers, or for the enterprise. I have experience in both spaces to share. In an enterprise environment, for example, often there are different constraints or greater separation of responsibilities across different teams.