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

0.1.3 • Public • Published

Netlify Plugin Env

Version License

This plugin helps to have your env variables separated by deploy context in a seamless way.

Why

It is pretty common to have multiple environments to test apps rigorously before promoting changes to production. This way, the app can be delivered with more confidence.

Netlify provides a great mechanism called deploy contexts. This mechanism allow to configure as many custom deploy contexts as you want, all you need is to add a new branch to your configuration. For instance, a branch called staging will match a deploy context called staging

That's great, isn't it? However there is a little limitation for configuring environment variables per deploy context. The only way to override an env variable for a context is through netlify.toml, which means code needs to be changed and sensitive information could be exposed.

So, this plugin aims to fix that.

Note @netlify-tools/cli can help with setting env variables by context

How it works

In order for this plugin to work properly env variables names need to have the format: [VARIABLE]_[DEPLOY-CONTEXT], so the plugin will check the process.env and will set for [VARIABLE] the value of [VARIABLE]_[DEPLOY-CONTEXT] if the current deploy context and [DEPLOY-CONTEXT] matches.

For instance:

AUTH_TOKEN=supersecret
AUTH_TOKEN_STAGING=secret@

the plugin will override the AUTH_TOKEN value with the one for AUTH_TOKEN_STAGING.

AUTH_SECRET === AUTH_TOKEN_STAGING === secret@

The next table show a few examples

Deploy Context Branch Deploy? Variable Notes
production --- AUTH_TOKEN_PRODUCTION predefined deploy context
deploy-preview --- AUTH_TOKEN_DEPLOY_PREVIEW predefined deploy context
branch-deploy --- AUTH_TOKEN_BRANCH_DEPLOY predefined deploy context
--- staging AUTH_TOKEN_STAGING
--- feature/login AUTH_TOKEN_FEATURE_LOGIN
deploy-preview staging AUTH_TOKEN_DEPLOY_PREVIEW_STAGING allow combination between predefined deploy context and branch deploys. This is great for preview having different configuration per preview

Usage

Add the plugin

Install it via npm

npm install --save-dev @netlify-tools/netlify-plugin-env

Install it via yarn

yarn add --dev @netlify-tools/netlify-plugin-env

Add a [[plugins]] entry to your netlify.toml file:

[[plugins]]
package = '@netlify-tools/netlify-plugin-env'

Package Sidebar

Install

npm i @netlify-tools/netlify-plugin-env

Weekly Downloads

0

Version

0.1.3

License

MIT

Unpacked Size

33.7 kB

Total Files

8

Last publish

Collaborators

  • jorgesuarezch