diff --git a/docs/docs/environment-variables.md b/docs/docs/environment-variables.md
index 9e7ea7207a4c3..f9fa9acebb4e0 100644
--- a/docs/docs/environment-variables.md
+++ b/docs/docs/environment-variables.md
@@ -21,6 +21,27 @@ API_URL=https://example.com/api
These variables will be available to your site as `process.env.API_URL`.
+In addition any variable in the environment prefixed with `GATSBY_` will be available.
+
+## Example
+
+```
+GATSBY_ASSETS_URL=http://s3.amazonaws.com/bucketname
+```
+
+```jsx
+// usage
+render() {
+ return (
+
+
+
+ )
+}
+```
+
+
+
> You can not override certain environment variables as some are used internally for optimizations during build
Reserved environment variables:
diff --git a/packages/gatsby/src/utils/webpack.config.js b/packages/gatsby/src/utils/webpack.config.js
index 4a78255b25823..3edc98828d925 100644
--- a/packages/gatsby/src/utils/webpack.config.js
+++ b/packages/gatsby/src/utils/webpack.config.js
@@ -64,11 +64,18 @@ module.exports = async (
return acc
}, {})
+ const gatsbyVarObject = Object.keys(process.env).reduce((acc, key) => {
+ if (key.match(/^GATSBY_/)) {
+ acc[key] = JSON.stringify(process.env[key])
+ }
+ return acc
+ }, {})
+
// Don't allow overwriting of NODE_ENV, PUBLIC_DIR as to not break gatsby things
envObject.NODE_ENV = JSON.stringify(env)
envObject.PUBLIC_DIR = JSON.stringify(`${process.cwd()}/public`)
- return envObject
+ return Object.assign(envObject, gatsbyVarObject)
}
debug(`Loading webpack config for stage "${stage}"`)