Skip to content

Commit cc9672b

Browse files
committed
doc: add documentation for runtime option
1 parent b169a21 commit cc9672b

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Here are some of the benefits of using `dotenv-run`:
1717
| Integration | Package | Status |
1818
| --------------- | ----------------------------------------- | ------ |
1919
| CLI | [@dotenv-run/cli](#dotenv-runcli) | ✅ |
20-
| Core | [@dotenv-run/core](#dotenv-runcore) | ✅ |
20+
| Core | [@dotenv-run/core](#dotenv-runcore) | ✅ |
2121
| ESBuild | [@dotenv-run/esbuild](#dotenv-runesbuild) | ✅ |
2222
| Rollup | [@dotenv-run/rollup](#dotenv-runrollup) | ✅ |
23-
| Vite | [@dotenv-run/rollup](#dotenv-runrollup) | ✅ |
24-
| Node.js preload | @dotenv-run/load | ✅ |
23+
| Vite | [@dotenv-run/rollup](#dotenv-runrollup) | ✅ |
24+
| Node.js preload | @dotenv-run/load | ✅ |
2525
| Angular | [@ngx-env/builder](#ngx-envbuilder) | ✅ |
2626

2727
## Quick start
@@ -152,6 +152,7 @@ await build({
152152
[`@ngx-env/builder`](https://www.npmjs.com/package/@ngx-env/builder) is a plugin for Angular CLI and a wrapper around `@dotenv-run/esbuild` or `@dotenv-run/webpack` that can be used to inject environment variables into your Angular applications.
153153

154154
- ✅ Official recommendation in [dotenv documentation](https://www.dotenv.org/docs/frameworks/angular/vercel) 🔥
155+
- ✅ Runtime environment variables (Experimental) 🎉
155156
- ✅ Webpack and ESBuild support 🚀
156157
- ✅ Easy to use, no configuration required
157158
- ✅ Up to date with latest Angular versions
@@ -216,6 +217,8 @@ Configuration options can be passed to `@ngx-env/builder` using `ngxEnv` section
216217
}
217218
```
218219

220+
If you want to update the environment variables at runtime, you can use the `runtime` option.
221+
219222
You can find the full `@ngx-env/builder` documentation [here](https://github.com/chihab/dotenv-run/tree/main/packages/angular).
220223

221224
### @dotenv-run/webpack

packages/angular/README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
- ✅ Official recommendation in [dotenv documentation](https://www.dotenv.org/docs/frameworks/angular/vercel) 🔥
1111
- ✅ Webpack and ESBuild support 🚀
12+
- ✅ Runtime environment variables (Experimental) 🎉
1213
- ✅ Loading priorities of environment variables with Monorepo Support ([Nx](https://nx.dev), [Turbo](https://turbo.build/), etc.) ✨
1314
- ✅ Easy to use, no configuration required
1415
- ✅ Up to date with latest Angular versions
@@ -227,6 +228,27 @@ You can also access the environment variables starting with `NG_APP_` in the `in
227228
</html>
228229
```
229230

231+
## Runtime Environment Variables (Experimental)
232+
233+
By default, environment variables are embedded during the build time which means they are static and cannot be changed at runtime.
234+
235+
If you want to change the environment variables at runtime, you can use the `runtime` option in the `angular.json` configuration.
236+
237+
```json
238+
"ngxEnv": {
239+
"prefix": "NG_APP_",
240+
"runtime": true
241+
}
242+
```
243+
244+
When you set the `runtime` option to `true`, a new environment file will be created during the build with the name `ngx-env.js` in the build output directory containing the environment variables that match the prefix. You can change the environment variables at runtime by modifying this file.
245+
246+
```ts
247+
globalThis._NGX_ENV_ = {
248+
NG_APP_VERSION: "10.0.0",
249+
};
250+
```
251+
230252
# Defining Environment Variables
231253

232254
## Command Line
@@ -471,19 +493,15 @@ Usage `process.env` might introduce typing issues depending on whether your work
471493
## Declare your environment variables in the generated `.env.d.ts` file
472494

473495
```ts
474-
interface ImportMeta {
475-
readonly env: ImportMetaEnv;
496+
declare interface Env {
497+
readonly NODE_ENV: string;
498+
// Replace the following with your own environment variables, for example:
499+
// readonly NG_APP_VERSION: string;
500+
[key: string]: any;
476501
}
477502

478-
interface ImportMetaEnv {
479-
/**
480-
* Built-in environment variable.
481-
* @see Docs https://github.com/chihab/dotenv-run/packages/angular#ng_app_env.
482-
*/
483-
readonly NG_APP_ENV: string;
484-
// Add your environment variables below
485-
// readonly NG_APP_API_URL: string;
486-
[key: string]: any;
503+
declare interface ImportMeta {
504+
readonly env: Env;
487505
}
488506
```
489507

packages/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-env/builder",
3-
"version": "17.3.0-alpha.0",
3+
"version": "17.3.0",
44
"description": "Easily inject environment variables into your Angular applications",
55
"author": "chihab <[email protected]>",
66
"homepage": "https://github.com/chihab/ngx-env/tree/main/packages/angular",

0 commit comments

Comments
 (0)