Angular's built-in environment files bake configuration into the build output, forcing a separate build per environment. This post presents two alternatives for externalizing environment config from the source code: fetching a JSON asset file before app bootstrap, or loading a JavaScript config into the window object before Angular initializes. Both approaches use an InjectionToken to provide the config through Angular's DI system. The JSON approach is preferred by the author for ease of replacement during release. A security reminder is included: all client-side config is publicly visible, so sensitive data must never be stored there.

8m read timeFrom timdeschryver.dev
Post cover image
Table of contents
Environment specific configurationThe problem with Angular environment filesThe solutionConclusion