Storybook: Auto-set a 'STORYBOOK' environment variable to 'true'

Created on 8 Sep 2020  路  3Comments  路  Source: storybookjs/storybook

Is your feature request related to a problem? Please describe.

When using different configuration for development, production and Storybook, it鈥檚 desirable to know whether we鈥檙e in a Storybook environment by querying process.env.STORYBOOK. For instance, a postcss.config.js file鈥檚 excerpt could look as follows:

module.exports = {
  plugins: {
    "postcss-import",
    "tailwindcss",
    "postcss-preset-env",

    // Simulate pseudos (only for Storybook)
    ...(process.env.STORYBOOK && { "postcss-pseudo-classes" })
}
  }
}

Describe the solution you'd like

Similarly to the convention of popular CI services, an environment variable for STORYBOOK should be set to true by default. It seems to blend well with Storybook鈥檚 existing env var handling mechanism.

Describe alternatives you've considered

Using cross-env for scripts defined in package.json. It鈥檚 error-prone and often forgotten by UNIX-only users who would prefer just STORYBOOK=true && start-storybook.

Are you able to assist bring the feature to reality?

No, unfortunately, I鈥檓 too busy at this time to familiarize myself with the codebase.

PN core feature request good first issue has workaround help wanted

All 3 comments

This is not stale.

@shilman
Can I try this?

Yo-ho-ho!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-beta.3 containing PR #12997 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zvictor picture zvictor  路  3Comments

arunoda picture arunoda  路  3Comments

MrOrz picture MrOrz  路  3Comments

alexanbj picture alexanbj  路  3Comments

wahengchang picture wahengchang  路  3Comments