Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Add environment variable related docs #38

Merged
merged 3 commits into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/docs/configurations/env-vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {stripIndent} from 'common-tags'

export default {
id: "env-vars",
title: "Using Environment Variables",
content: stripIndent`
Sometimes, we may use configuration items inside Storybook. It might be a theme color, some client secret, or a JSON string. So, we usually tend to hard code them.

But you can expose those configurations via "environment variables." For that, you need to prefix your environment variables with \`STORYBOOK_\` prefix.

For an example, let's expose two environment variables like this:

~~~sh
STORYBOOK_THEME=red STORYBOOK_DATA_KEY=12345 npm run storybook
~~~

Then we can access these environment variables anywhere inside our JS code like below:

~~~js
console.log(process.env.STORYBOOK_THEME)
console.log(process.env.STORYBOOK_DATA_KEY)
~~~

> Even though we can access these env variables anywhere in the client side JS code, it's better to use them only inside stories and inside the main Storybook config file.

## Build time environment variables

You can also pass these environment variables when you are [building your storybook](http://localhost:3000/docs/basics/exporting-storybook) with \`build-storybook\`.

Then they'll be hard coded to the static version of your Storybook.

## NODE_ENV env variable

In addition to the above prefixed environment variables, you can also pass the NODE_ENV variable to Storybook. But, you normally don't need to do that since we set a reasonable default value for it.

* When running \`npm run storybook\`, we set NODE_ENV to 'development'
* When building storybook, we set NODE_ENV to 'production'
`
};
1 change: 1 addition & 0 deletions src/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const data = {
require('./configurations/custom-babel-config').default,
require('./configurations/add-custom-head-tags').default,
require('./configurations/serving-static-files').default,
require('./configurations/env-vars').default,
require('./configurations/cli-options').default,
]
},
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ReactDOM.render(
(
<Router
history={browserHistory}
render={applyRouterMiddleware(useScroll())}
>
<Route path="/" component={Homepage} />
<Route path="/docs(/:sectionId/(:itemId))" component={Docs} />
Expand Down