@microbackend/plugin-env-vars
v1.0.1
Published
Micro-backend environment variables plugin
Downloads
6
Readme
@microbackend/plugin-env-vars
Microbackend plugin to inject environment variables into process.env
.
Installation
npx microbackend plugin add @microbackend/plugin-env-vars
Usage
import createPluginConfig from "@microbackend/plugin-core/build/webpack.build";
await createPluginConfig({
pluginOptions: {
"@microbackend/plugin-env-vars": {
additionalEnvVariables: { ENV_2: "2" },
dumpToProcessEnv2: true,
requiredEnvVariables: ["ENV_1", "ENV_2"],
},
},
});
The above configuration does the following:
- Extract the environment variables in
env.${environment}
, whereenvironment
is determined byNODE_ENV
. For example, ifNODE_ENV
isdevelopment
, the values inenv.development
will be used. - Extract additional variables passed to
additionalEnvVariables
. - Check that the keys specified to
requiredEnvVariables
point to valid environment variable values. If they do not, an error will be thrown. This is useful for compile-time checks against missing environment variables. - Inject all the collected variables into
process.env
usingDefinePlugin
, which can be accessed during runtime usingprocess.env.ENV1
(const { ENV_1 } = process.env
will not work). - If
dumpToProcessEnv2
is specified, dump all environment variables toprocess.env2
as well. This is useful during development when we want to view all currently available variables (e.g.console.log(process.env2)
).