TypeScript environment variables

let's say I have a block of code that I would only like to be present (or run) in an intermediate environment. I set the environment variable in this enivronment (say ENV = 'staging'), is there a way for TypeScript to access this variable at compile time?

example:

if (Enivronment['ENV'] == 'staging') console.log('testing');

which will be compiled (redundant but effective) if ('staging' == 'staging') ... in the above environment?

+6
source share
1 answer

is there a way for typeScript to access this variable at compile time

Yeah. Prefer to use process.env , which works the same as in node and can be used with webpack using --define.

More details

An example showing how to use it to create output: https://basarat.gitbooks.io/typescript/content/docs/tips/build-toggles.html

+1
source

Source: https://habr.com/ru/post/1012357/


All Articles