@grund/constants v0.0.85
@grund/constants
The purpose of this package is to handle and enhance environment variables and expose and interface that provides basic use of commond constants in pretty much any project. It is also use internally by many other @grund packages.
Runtime overrides
Environment variables (or in this case; "constants") can be used in two different situations; application
and CLI
.
When an application is bundled and shipped we sometimes want to control which variables are overridable and which are not (this of course only applies for NodeJS
applications - browser constants are not overridable). This is where the packages @grund/babel-preset
and @grund/babel-plugin-inline-env
comes in which allows us to do just this.
In a CLI (such as @grund/cli
or webpack
) we might want either rely on the running environment variables (e.g. NODE_ENV
) or we might want to be able to change them for a specific command (e.g. NODE_ENV=production yarn webpack
).
To solve for these two cases and still be able to use @grund/constants
wherever, the implementation is as follows;
- If
GrundContainer
has an instance of theconstants
key, then we will use this as a single source of the constants. This will be the case in most (if not all?) applications. - Otherwise (if
constants
is not set), we will useprocess.env
as a fallback for all environment values. This is targetted more towards CLI usage. OBS. this also gives the developer the responsibility to make sure thatNODE_ENV
andRUNTIME_ENV
are set.