Skip to content

Commit 6170713

Browse files
authored
Replace webpack with Vite for storybook (#3713)
1 parent a953ec0 commit 6170713

File tree

11 files changed

+577
-1243
lines changed

11 files changed

+577
-1243
lines changed

apps/storybook/.storybook/main.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
1-
import type { StorybookConfig } from '@storybook/react-webpack5';
1+
import type { StorybookConfig } from '@storybook/react-vite';
22

33
const config: StorybookConfig = {
44
stories: [
55
//
66
'../stories/**/*.mdx',
77
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
88
],
9-
addons: ['@storybook/addon-webpack5-compiler-swc', '@storybook/addon-docs'],
9+
addons: ['@storybook/addon-docs'],
1010
framework: {
11-
name: '@storybook/react-webpack5',
11+
name: '@storybook/react-vite',
1212
options: {
1313
builder: {},
1414
// enable React strict mode
1515
strictMode: true,
1616
},
1717
},
18-
19-
swc: (config: any) => ({
20-
...config,
21-
jsc: {
22-
...config?.jsc,
23-
transform: {
24-
...config?.jsc?.transform,
25-
react: {
26-
// Do not require importing React into scope to use JSX
27-
runtime: 'automatic',
28-
},
29-
},
30-
},
31-
}),
3218
};
3319
export default config;

apps/storybook/.storybook/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Preview } from '@storybook/react-webpack5';
1+
import type { Preview } from '@storybook/react-vite';
22
import './preview.css';
33

44
const preview: Preview = {

apps/storybook/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"lint": "eslint --max-warnings 0 .",
88
"dev": "storybook dev -p 6006",
99
"build": "storybook build",
10+
"serve": "serve storybook-static -l 6006",
1011
"typecheck": "tsc --noEmit"
1112
},
1213
"dependencies": {
@@ -22,16 +23,18 @@
2223
"@chromatic-com/storybook": "^4.1.1",
2324
"@repo/eslint-config": "workspace:*",
2425
"@repo/typescript-config": "workspace:*",
25-
"@storybook/addon-webpack5-compiler-swc": "^4.0.1",
26-
"@storybook/react-webpack5": "^9.1.15",
26+
"@storybook/addon-docs": "^9.1.15",
27+
"@storybook/addon-vitest": "^9.1.15",
28+
"@storybook/react-vite": "^9.1.15",
2729
"@types/form-serialize": "^0",
2830
"@types/react": "^19.2.2",
2931
"@types/react-dom": "^19.2.2",
3032
"eslint": "^9.38.0",
33+
"serve": "^14.2.5",
3134
"storybook": "^9.1.15",
3235
"typescript": "^5.9.3",
3336
"eslint-plugin-storybook": "^9.1.15",
34-
"@storybook/addon-docs": "^9.1.15",
35-
"@storybook/addon-vitest": "^9.1.15"
37+
"vite": "^6.2.0",
38+
"vitest": "^3.1.1"
3639
}
3740
}

apps/storybook/stories/one-time-password-field.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { unstable_OneTimePasswordField as OneTimePasswordField, Separator } from 'radix-ui';
33
import { Dialog as DialogPrimitive } from 'radix-ui';
44
import dialogStyles from './dialog.stories.module.css';
5-
import type { Meta, StoryObj } from '@storybook/react-webpack5';
5+
import type { Meta, StoryObj } from '@storybook/react-vite';
66
import { userEvent, within, expect } from 'storybook/test';
77
import styles from './one-time-password-field.stories.module.css';
88

apps/storybook/stories/password-toggle-field.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import type { Meta, StoryObj } from '@storybook/react-webpack5';
2+
import type { Meta, StoryObj } from '@storybook/react-vite';
33
import { useArgs } from 'storybook/preview-api';
44
import { unstable_PasswordToggleField as PasswordToggleField } from 'radix-ui';
55
import styles from './password-toggle-field.stories.module.css';

cypress.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default defineConfig({
44
viewportWidth: 1024,
55
viewportHeight: 768,
66
fixturesFolder: false,
7+
defaultCommandTimeout: 20_000,
78
e2e: {
89
// TODO There is a bug (I think) in Cypress that results in the page
910
// navigating to `about:blank` after certain tests run. Unclear why at this

cypress/support/commands.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// @ts-check
2+
/// <reference types="cypress" />
3+
/// <reference types="./index.d.ts" />
4+
15
// ***********************************************
26
// This example commands.js shows you how to
37
// create various custom commands and overwrite
@@ -24,6 +28,10 @@
2428
// -- This will overwrite an existing command --
2529
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
2630

31+
Cypress.Commands.add('visitStorybook', (options) => {
32+
return cy.visit('iframe.html', options);
33+
});
34+
2735
Cypress.Commands.add('visitStory', (storyName, options) => {
2836
return cy.visit(`iframe.html?id=components-${storyName}`, options);
2937
});

cypress/support/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
declare namespace Cypress {
22
// eslint-disable-next-line @typescript-eslint/no-unused-vars
33
interface Chainable<Subject> {
4-
visitStory(storyName: string, options?: Partial<Cypress.VisitOptions>): Chainable<any>;
4+
visitStorybook(options?: Partial<Cypress.VisitOptions>): Cypress.Chainable<Cypress.AUTWindow>;
5+
visitStory(
6+
storyName: string,
7+
options?: Partial<Cypress.VisitOptions>
8+
): Cypress.Chainable<Cypress.AUTWindow>;
59
}
610
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"test": "vitest",
1111
"test:ci": "vitest run && pnpm cypress:ci",
1212
"storybook": "BROWSER=none pnpm --filter=@repo/storybook run dev -p 9009",
13+
"storybook:build": "BROWSER=none pnpm --filter=@repo/storybook run build",
14+
"storybook:serve": "pnpm --filter=@repo/storybook run serve",
1315
"cypress:ci": "start-server-and-test 'pnpm dev' http://localhost:9009 'pnpm cypress:install && pnpm cypress:run'",
1416
"cypress:install": "cypress install",
1517
"cypress:run": "cypress run",
@@ -61,7 +63,7 @@
6163
"react-dom": "^19.2.0",
6264
"react-test-renderer": "^19.0.0",
6365
"replace-in-files": "^3.0.0",
64-
"start-server-and-test": "2.0.3",
66+
"start-server-and-test": "^2.1.2",
6567
"tsup": "^8.3.6",
6668
"typescript": "^5.9.3",
6769
"vite": "^6.2.0",

0 commit comments

Comments
 (0)