GithubHelp home page GithubHelp logo

pauliescanlon / gatsby-recipe-storybook-js Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 12 KB

A Gatsby recipe to add Storybook to your JavaScript Gatsby project ๐Ÿณ

JavaScript 100.00%
gatsby gatsbyjs gatsby-recipe

gatsby-recipe-storybook-js's Introduction

gatsby-recipe-storybook-js

gatsby-recipe-storybook-js

There are two main problems with Gatsby and Storybook, you'll most likely experience Storybook build errors if you're doing either of the following.

  1. You're using <Link /> imported from gatsby
  2. You have components with embedded GraphQL queries

These are not problems with either Gatsby or Storybook but there are one or two things we need to do in order to get the two playing nicely together. The main reasons we get Storybook build errors are outlined below.

  • Gatsby exports as ES6 and Storybook by default expects all code to be ES5 / CommonJs.
  • The gatsby develop and gatsby build steps remove GraphQL queries, Storybook by default does not.

This recipe will automate the following steps

  • Install babel plugins and presets
  • Install babel-plugin-react-docgen
  • Install Storybook React NPM packages and addons
  • Create custom Storybook webpack config (main.js) for js|jsx
  • Configure Storybook / Gatsby Link settings (preview.js)
  • Create example Link stories
  • Add Storybook npm scripts to package.json

Wanna give it a try?

gatsby recipes https://raw.githubusercontent.com/PaulieScanlon/gatsby-recipe-storybook-js/master/gatsby-recipe-storybook-js.mdx

I've written a blog post about this recipe if you're looking for a little more information: https://paulie.dev/posts/2020/04/gatsby-recipe-storybook-js/

gatsby-recipe-storybook-js's People

Contributors

pauliescanlon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gatsby-recipe-storybook-js's Issues

__BASE_PATH__ is not defined (gatsby 3)

thanks for a great recipe!

i was able to run storybook finally on gatsby 3

one issue i notice - BASE_PATH is not defined

Screen Shot 2021-03-08 at 3 58 38 PM

it is an easy fix in .storybook/preview.js

global.__PATH_PREFIX__ = "";
//add this line
global.__BASE_PATH__ = "";

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.