Skip to content
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 Storybook (Vite) framework package #10064

Merged
merged 68 commits into from
Jun 4, 2024

Conversation

arimendelow
Copy link
Contributor

@arimendelow arimendelow commented Feb 25, 2024

Overview

This PR is the first step to migrating our Storybook integration from relying on Webpack to relying on Vite. Specifically, this PR:

  • Adds the Storybook framework package for RedwoodJS.
    • This follows the modern Storybook pattern for providing required configuration for getting Storybook to work with a given framework/metaframework.
    • For comparison, our current Webpack Storybook setup was written before framework packages were a thing, so its architected very differently. See the @redwoodjs/testing package for more information.
    • The eventual goal is for this package to move into the Storybook codebase and be "officially" supported.
    • This package was forked from the react-vite framework package.
  • Adds the storybook-vite CLI package, which is based on the existing storybook CLI package. The CLI package does two important things before running the Storybook command:
    • Checks if the necessary project-side config files exist yet, and creates them if they don't.
    • Creates the Mock Service Worker, which is necessary for Cell mocking.

Importantly, the architecture of this (including duplicating files, etc.) is based on the eventual goal of removing the older Storybook integration files.

Proof

This screen recording shows that the following works:

  • Router
  • Nested cells (waterfall)
  • Auth

sbv demo

Details

This framework package is based on the proof of concept of getting Storybook working on RedwoodJS with Vite, which is documented here.

Please see that and official Storybook framework package documentation to understand implementation details.

Outstanding

  • The console outputs are a bit noisy, and it seems like it's just noise. Do we want to address/silence this?
  • Testing?
  • Cleanup?
  • Finalize how we want to roll this out. For example:
    • Do we want to add a console message to the current CLI that it'll be removed in a future/next major?
    • How do we want to address the different CLI packages? Some options:
      • Temporarily keep the existing one as yarn redwood storybook, and make the new one yarn redwood storybook-vite.
      • Make the existing one yarn redwood storybook-webpack.
        • I'm concerned that folks will not be aware of this, causing friction.
  • Based on the above, write migration guide.
  • ???

Trying it out

First step is, of course, pulling down this branch.

I've been testing this with the generated test project. If you want to do that, from the framework repo, first run:

yarn run build:test-project ../for-testing-storybook-vite

Then, over in your project, run yarn rwfw project:tarsync so that the module resolutions point to the ones in this branch.

Then, I think because it hasn't yet been published anywhere, you'll need to manually add the new CLI package (yarn complains about not being able to find the packument when I try to get the CLI package to autoinstall):

yarn add -D @redwoodjs/cli-storybook-vite@7

Then, run:

yarn rw sbv

Your browser should then open to Storybook!

Tobbe and others added 6 commits May 23, 2024 10:07
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
@arimendelow arimendelow changed the title [DRAFT] Add Storybook (Vite) framework package Add Storybook (Vite) framework package May 29, 2024
@Tobbe Tobbe added the release:feature This PR introduces a new feature label May 31, 2024
@Tobbe Tobbe added this to the next-release milestone May 31, 2024
@Tobbe
Copy link
Member

Tobbe commented Jun 3, 2024

Left to do (in this, or separate PR)

  • Add to CI by copying existing smoke test and make it run with sbv
  • unit test that checks that the new framework files are added during setup
  • Add message to yarn rw sb telling the user to switch to sbv
  • Write some kind of migration guide for current webpack SB users
    • Do this as a forum post
  • Update https://redwoodjs.com/docs/storybook to mention new sbv command
    • Separate page for the Webpack version of SB
    • Another page for the Vite version

@Tobbe Tobbe merged commit 285d657 into redwoodjs:main Jun 4, 2024
42 checks passed
Josh-Walker-GM added a commit that referenced this pull request Jun 6, 2024
Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
@arimendelow arimendelow deleted the ari/add-storybook-framework-package branch June 7, 2024 23:37
@arimendelow arimendelow restored the ari/add-storybook-framework-package branch June 9, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants