-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add: docs for storybook #9120
add: docs for storybook #9120
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Would be kinda nice if we could slightly clean up the webpack config generation, but works well enough 🤷♂️
Thanks for this!
|
||
```js | ||
module.exports = (baseConfig, env, defaultConfig) => { | ||
// Transpile Gatsby module because Gastby includes un-transpiled ES6 code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an open issue for this. Maybe I'll fix this today and add a transpiled main
field?
See #8821
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once #9123 is merged, we can remove this 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#9123 did fix my situation where i was unit testing in a context that needed common-js, but i'm still seeing raw jsx in the module
defined by the gatsby
package, which causes problems for my storybook instance that was working before upgrading to v2.
normally module
is still transpiled to some degree so that that it is at least valid js (which jsx is not) at some lowest common denominator, but still uses es module import
/export
. i normally handle producing es-module for module
and common-js for main
using rollup. if this were in place, there shouldn't be a need to transpile the gatsby
package further when depending on it in a storybook project, etc.
if the team would be open to a build step that would produce both main
and module
with a process similar to this, i'd be happy to contribute. thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i opened a PR with a start toward this type of config to give a little more detail around the approach i typically use
title: Visual Testing with Storybook | ||
--- | ||
|
||
Knowing your components look as intended in every permutation is not only a great way to test them visually, but also provides "living documentation" for them. This makes it easier for teams to 1) know what components are available to them in a given project and 2) what props those components accept and what all of the states of that component are. As your project grows over time having this information available will be invaluable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a quick one line defining what Storybook is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just copy directly from https://storybook.js.org/basics/introduction/
not sure if you're interested in including information about automating this further, but Percy provides a nice integration to very easily use their service with an existing storybook setup. |
If anyone needs help / info with Percy I'd love to help! I'm starting at the support manager later this month. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few little corrections, and some suggestions to make things a bit less wordy, as people generally don't read long text on-screen.
|
||
## Setting up your environment | ||
|
||
In order to set up Storybook you will need to install a few dependencies and then do some custom configuration to make Storybook work with your Gatsby environment. The first thing is to get the Storybook CLI installed if you don't have it already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be less wordy, perhaps:
In order to set up Storybook you will need to install a few dependencies and then do some custom configuration to make Storybook work with your Gatsby environment. The first thing is to get the Storybook CLI installed if you don't have it already. | |
To set up Storybook you need to install dependencies and do some custom configuration. First, install the Storybook CLI. |
} | ||
``` | ||
|
||
Next we need up make some adjustments to Storybook's default `webpack` configuration so that we can tranpile Gatsby source files, as well as ensure we have all the necessary `babel` plugins we need to transpile Gatsby components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next we need up make some adjustments to Storybook's default `webpack` configuration so that we can tranpile Gatsby source files, as well as ensure we have all the necessary `babel` plugins we need to transpile Gatsby components. | |
Next we make some adjustments to Storybook's default `webpack` configuration so we can transpile Gatsby source files, and to ensure we have the necessary `babel` plugins to transpile Gatsby components. |
|
||
A full guide to writing stories is beyond the scope of this guide, but we'll take a look at creating a story. | ||
|
||
First, create the story file. Storybook looks for all files with a `.story.js` extension and loads them into Storybook for you. Generally you will want your stories near where the component is defined, however since this Gatsby, if you want stories for your pages, you will have to create those files outside of the `pages` directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, create the story file. Storybook looks for all files with a `.story.js` extension and loads them into Storybook for you. Generally you will want your stories near where the component is defined, however since this Gatsby, if you want stories for your pages, you will have to create those files outside of the `pages` directory. | |
First, create the story file. Storybook looks for all files with a `.story.js` extension and loads them into Storybook for you. Generally you will want your stories near where the component is defined, however since this is Gatsby, if you want stories for your pages, you will have to create those files outside of the `pages` directory. |
This has been hanging out for a while, so I incorporated @KyleAMathews' changes and am going to merge this in. Thanks @kkemple! @hugovk thanks for the suggestions -- perhaps you can open a PR with them and tag @kkemple or @shannonbux ? |
@travi I think Percy docs would be great! Might make sense to make it it's own thing though |
…xt on-screen (#9494) As suggested by @calcsam in #9120 (comment), here's my review comments in its own PR. Follows https://www.gatsbyjs.org/docs/gatsby-style-guide/#write-concisely cc @kkemple @shannonbux Also use “you” as the pronoun, following the [style guide](https://www.gatsbyjs.org/docs/gatsby-style-guide/#use-you-as-the-pronoun). <!-- Q. Which branch should I use for my pull request? A. Use `master` branch (probably). Q. Which branch if my change is a bug fix for Gatsby v1? A. In this case, you should use the `v1` branch Q. Which branch if I'm still not sure? A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :) Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2. Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/ -->
* add: docs for storybook * Update visual-testing-with-storybook.md
…xt on-screen (gatsbyjs#9494) As suggested by @calcsam in gatsbyjs#9120 (comment), here's my review comments in its own PR. Follows https://www.gatsbyjs.org/docs/gatsby-style-guide/#write-concisely cc @kkemple @shannonbux Also use “you” as the pronoun, following the [style guide](https://www.gatsbyjs.org/docs/gatsby-style-guide/#use-you-as-the-pronoun). <!-- Q. Which branch should I use for my pull request? A. Use `master` branch (probably). Q. Which branch if my change is a bug fix for Gatsby v1? A. In this case, you should use the `v1` branch Q. Which branch if I'm still not sure? A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :) Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2. Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/ -->
* add: docs for storybook * Update visual-testing-with-storybook.md
…xt on-screen (gatsbyjs#9494) As suggested by @calcsam in gatsbyjs#9120 (comment), here's my review comments in its own PR. Follows https://www.gatsbyjs.org/docs/gatsby-style-guide/#write-concisely cc @kkemple @shannonbux Also use “you” as the pronoun, following the [style guide](https://www.gatsbyjs.org/docs/gatsby-style-guide/#use-you-as-the-pronoun). <!-- Q. Which branch should I use for my pull request? A. Use `master` branch (probably). Q. Which branch if my change is a bug fix for Gatsby v1? A. In this case, you should use the `v1` branch Q. Which branch if I'm still not sure? A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :) Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2. Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/ -->
Added docs for using Storybook with Gatsby!