gatsby-plugin-config
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="1.0.4"></a> | ||
## [1.0.4](https://github.com/birkir/gatsby-plugin-config/compare/v1.0.3...v1.0.4) (2018-10-22) | ||
<a name="1.0.3"></a> | ||
@@ -7,0 +12,0 @@ ## [1.0.3](https://github.com/birkir/gatsby-plugin-config/compare/v1.0.2...v1.0.3) (2018-10-22) |
{ | ||
"name": "gatsby-plugin-config", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Gatsby config", | ||
@@ -10,3 +10,10 @@ "main": "build/main/index.js", | ||
"license": "MIT", | ||
"keywords": [], | ||
"keywords": [ | ||
"gatsby", | ||
"gatsby-plugin", | ||
"config", | ||
"dotenv", | ||
"environment variables", | ||
"env" | ||
], | ||
"scripts": { | ||
@@ -13,0 +20,0 @@ "info": "npm-scripts-info", |
# gatsby-plugin-config | ||
Config plugin for gatsby | ||
Plugin for gatsby to handle environment variables with ease. | ||
- [x] Built in dotenv | ||
- [x] Handle empty strings | ||
- [x] Strip out GATSBY_ prefix | ||
## Usage | ||
Given the environment variable `GATSBY_FLAG=5`: | ||
Install with npm | ||
```bash | ||
npm install gatsby-plugin-config -S | ||
``` | ||
Import the plugin with import | ||
```js | ||
import config from 'gatsby-plugin-config'; | ||
``` | ||
console.log(config.FLAG); // 5 | ||
console.log(config.NOPE); // undefined | ||
``` | ||
### GATSBY variables | ||
Variables prefixed with `GATSBY_` are accessiable from the client side by default. This plugin allows you to query them without the prefix. | ||
```js | ||
// process.env.GATSBY_API_URL | ||
config.API_URL | ||
``` | ||
### Empty variables | ||
You don't have to match empty variables anymore like this: | ||
```js | ||
if (process.env.GATSBY_IS_STAGING && process.env.GATSBY_IS_STAGING !== '') { | ||
// do something | ||
} | ||
``` | ||
You can now just do: | ||
```js | ||
if (config.IS_STAGING) { | ||
// you're done | ||
} | ||
``` | ||
### gatsby-config.js | ||
Usage in files without module system (like gatsby-config / gatsby-node etc.) | ||
```js | ||
const config = require('gatsby-plugin-config').default; | ||
module.exports = { | ||
siteMetadata: { | ||
title: config.SITE_TITLE, | ||
}, | ||
}; | ||
``` | ||
### Dotenv | ||
You can keep separate dotenv files for each environment in the project root. See https://github.com/motdotla/dotenv for more details. | ||
``` | ||
.env.development | ||
.env.staging | ||
.env.production | ||
``` | ||
The format is simply `.env.${process.env.NODE_ENV}` | ||
## Troubleshooting | ||
Please file a bug if any issues occour. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10569
79