Enables access to process.env
in both node and browser packages (your code needs to rely on wepback or bundler that understands node environment).
This definition list of env variables is maintained manually and should be extended as needed.
{
"compilerOptions": {
"types": ["environment"]
}
}
Now you can use process.env
global with strict type checking:
// @ExpectType string
export function log(...messages: Array<string>) {
if (process.env.NODE_ENV === 'development') {
console.log(...messages);
}
// $ExpectError - 'prod' is not defined, did you mean to 'production' ?
if (process.env.NODE_ENV === 'prod') {
// do something
}
}
Add new env variables as needed
Example:
// Adding NX_ENV env variable
// ↓↓↓
interface ExtendedProcessEnv {
NODE_ENV?: 'production' | 'development' | 'test';
CI?: string;
TF_BUILD?: string;
+ NX_ENV?: string
}