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

Storybook 8 #1147

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 9 additions & 14 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import turbosnap from "vite-plugin-turbosnap";
import {dirname, join} from "path";
import viteConfig from "../dev/vite.config";
import {mergeConfig} from "vite";

import type {StorybookConfig} from "@storybook/react-vite";

function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
}

const config: StorybookConfig = {
framework: "@storybook/react-vite",
framework: getAbsolutePath("@storybook/react-vite"),

stories: [
// NOTE(jeremy): This glob is extremely finicky! I would have written
Expand All @@ -21,9 +25,9 @@ const config: StorybookConfig = {
],

addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-a11y",
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@storybook/addon-a11y"),
],

// NOTE(kevinb): We customize the padding a bit so that so that stories
Expand Down Expand Up @@ -54,15 +58,6 @@ const config: StorybookConfig = {
},
// Fix from: https://github.com/storybookjs/storybook/issues/25256#issuecomment-1866441206
assetsInclude: ["/sb-preview/runtime.js"],
plugins:
configType === "PRODUCTION"
? [
turbosnap({
// This should be the base path of your storybook. In monorepos, you may only need process.cwd().
rootDir: config.root ?? process.cwd(),
}),
]
: [],
});
},

Expand Down
2 changes: 2 additions & 0 deletions dev/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import {resolve, dirname, join} from "node:path";

import react from "@vitejs/plugin-react";
import glob from "fast-glob";
import {defineConfig} from "vite";

Expand All @@ -20,6 +21,7 @@ export default defineConfig({
// Dev/Storybook environment.
"process.env.STORYBOOK": JSON.stringify(true),
},
plugins: [react({jsxRuntime: "automatic"})],
resolve: {
alias: {
hubble: resolve(__dirname, "../vendor/hubble/hubble.js"),
Expand Down
20 changes: 8 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-replace": "^4.0.0",
"@sheerun/mutationobserver-shim": "^0.3.3",
"@storybook/addon-a11y": "^7.6.17",
"@storybook/addon-actions": "^7.6.17",
"@storybook/addon-controls": "^7.6.17",
Comment on lines -44 to -45
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actions, controls, and viewport addons are bundled into the "essentials" addon and so we don't need to depend on them separately.

https://storybook.js.org/integrations/tag/essentials

"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-links": "^7.6.17",
"@storybook/addon-viewport": "^7.6.17",
"@storybook/react": "^7.6.17",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"@storybook/react" is a dependency of "@storybook/react-vite" so having a direct dependency is redundant.

"@storybook/react-vite": "^7.6.17",
"@storybook/addon-a11y": "^8.0.10",
"@storybook/addon-essentials": "^8.0.10",
"@storybook/addon-links": "^8.0.10",
"@storybook/react-vite": "^8.0.10",
"@swc-node/register": "^1.6.6",
"@swc/core": "^1.3.68",
"@testing-library/jest-dom": "^5.15.0",
Expand All @@ -62,6 +58,7 @@
"@types/underscore": "^1.11.4",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@vitejs/plugin-react": "^4.2.1",
"ancesdir": "^3.1.0",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
Expand Down Expand Up @@ -116,12 +113,11 @@
"rollup-plugin-preserve-shebangs": "^0.2.0",
"rollup-plugin-styles": "^4.0.0",
"sloc": "^0.2.1",
"storybook": "^7.6.17",
"storybook": "^8.0.10",
"style-loader": "^3.3.3",
"typescript": "^5.4.2",
"typescript-coverage-report": "^0.7.0",
"vite-plugin-istanbul": "^5.0.0",
"vite-plugin-turbosnap": "^1.0.3",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turbosnap is now built into the "@storybook/react-vite" bundle and can be enabled with the standard --stats-json argument (see line 146 of this file).

"vite-plugin-istanbul": "^6.0.2",
"winston": "^3.7.2"
},
"resolutions": {
Expand All @@ -147,7 +143,7 @@
"test": "yarn jest",
"storybook": "storybook dev -p 6006",
"start": "storybook dev -p 6006",
"build-storybook": "storybook build",
"build-storybook": "storybook build --stats-json",
"cypress": "cypress open --component",
"cypress:ci": "cross-env BABEL_COVERAGE=1 cypress run --component --env CYPRESS_COVERAGE=1",
"format": "prettier --write .",
Expand Down