1.0.3 • Published 4 years ago

netlify-plugin-environment-variables v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

netlify-plugin-environment-variables

npm version npm downloads

Replace the value of environment variables on Netlify at build time based on deploy contexts.

Installation

For file-based installation, install the package first.

npm install netlify-plugin-environment-variables --save-dev

Add the following lines to your netlify.toml file.

[[plugins]]
package = 'netlify-plugin-environment-variables'

Usage

This plugin will replace the value of your environment variables based on deploy contexts.

Read more about deploy contexts here.

All the values of environment variables will be automatically replaced by the value environment variables with context suffix.

contextsdescriptionsuffix
Branch deployDeploys from branches that are not the site’s main production branch_BRANCH_DEPLOY
Deploy previewThe previews that are build for pull/merge requests_DEPLOY_PREVIEW
Branch namesCustom deploy contexts_BRANCH_NAME

For example, a development branch would trigger this plugin to automatically replace YOUR_ENVIRONMENT_VARIABLE with the value of YOUR_ENVIRONMENT_VARIABLE_DEVELOPMENT if it exists.

So, in your Netlify's Environment menu, you set your environment variables like this:

API_URL=https://example.com/api
API_URL_DEVELOPMENT=https://staging.example.com/api

All branch names that contain '-' or '/' will be replaced with '_'. So if you have a feat/branch or feat-branch branch, it will be changed to FEAT_BRANCH.

For master branch or production contexts, no need to setup environment variable with suffix.

If you prefer use a prefix rather than a suffix, set suffix to false in the plugins inputs below.

[[plugins]]
package = 'netlify-plugin-environment-variables'
  [plugins.inputs]
  suffix = false
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago