Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-plugin-config

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-config - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

5

CHANGELOG.md

@@ -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)

11

package.json
{
"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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc