@microbackend/plugin-env-vars
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@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}, where environment is determined by NODE_ENV. For example, if NODE_ENV is development, the values in env.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 using DefinePlugin, which can be accessed during runtime using process.env.ENV1 (const { ENV_1 } = process.env will not work).
  • If dumpToProcessEnv2 is specified, dump all environment variables to process.env2 as well. This is useful during development when we want to view all currently available variables (e.g. console.log(process.env2)).

Readme

Keywords

none

Package Sidebar

Install

npm i @microbackend/plugin-env-vars

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

11.7 kB

Total Files

9

Last publish

Collaborators

  • protoman92
  • haipham