New
You're viewing older docs for version 6.0. View latest docs

Environment variables

You can use environment variables in Storybook to change its behaviour in different “modes”. If you supply an environment variable prefixed with STORYBOOK_, it will be available in process.env:

Terminal
Loading...

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

You can also access these variables in your custom <head>/<body> using the substitution %STORYBOOK_X%, for example: %STORYBOOK_THEME% will become red.

If using the environment variables as attributes or values in JavaScript, you may need to add quotes, as the value will be inserted directly. e.g. <link rel="stylesheet" href="%STORYBOOK_STYLE_URL%" />

You can also pass these environment variables when you are building your Storybook with build-storybook.

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

Was this page helpful?

Markdown accepted ([link text](url), _italic_, **bold**, etc). Your anonymous feedback will be posted publicly on GitHub.

✍️ Edit on GitHub – PRs welcome!
Storybook
Join the community
6,565 developers and counting
WhyWhy StorybookComponent-driven UI
DocsGuidesTutorialsChangelogTelemetryStatus
CommunityAddonsGet involvedBlog
ShowcaseExploreProjectsComponent glossary
Open source software
Storybook

Maintained by
Chromatic
Special thanks to Netlify and CircleCI