Skip to content

Commit aaa3eb5

Browse files
committed
adds usage of env variables
1 parent a40f9e6 commit aaa3eb5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

webpack.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,40 @@ More env flags that are usually passed by the CLI automatically:
4545
- `--env.platform=<platform>` - for specifying the platform to use. Can be `android` or `ios`, or a custom platform in the future.
4646
- `--env.hmr` - `true` if building with HMR enabled
4747

48+
#### Using flags at runtime
49+
50+
In your app logic you can access `env` variables like the following:
51+
52+
```js
53+
if (process.env.production) {
54+
// this is a build executed with the `--env.production` flag
55+
// typically this would be your release build
56+
} else {
57+
// this is a debug/dev build
58+
}
59+
```
60+
61+
::: tip Note
62+
If you want to check if you are in Dev or Release mode you can also use:
63+
64+
```js
65+
if (__DEV__) {
66+
// this is dev builds
67+
}
68+
```
69+
70+
:::
71+
72+
#### Using a .env file
73+
74+
You can add a `.env` file to your project root and add any values to it and access those at runtime.
75+
76+
```js
77+
if (process.env.VAR_NAME) {
78+
// do work here if the variable is true
79+
}
80+
```
81+
4882
### CLI flags
4983

5084
When running a NativeScript app the following flags have an effect on the webpack config:

0 commit comments

Comments
 (0)