Skip to content

Commit

Permalink
Use Vite for Storybook, instead of webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuth committed Sep 7, 2024
1 parent 574f329 commit 694d4c6
Show file tree
Hide file tree
Showing 4 changed files with 524 additions and 1,345 deletions.
76 changes: 10 additions & 66 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,17 @@
import path from 'node:path';
import type {StorybookConfig} from '@storybook/react-webpack5';
import type {StorybookConfig} from '@storybook/react-vite';

export default {
addons: [
'@storybook/addon-a11y',
'@storybook/addon-essentials',
'@storybook/addon-webpack5-compiler-swc',
],
core: {
disableTelemetry: true,
},
framework: {
name: '@storybook/react-webpack5',
options: {},
},
stories: ['../app'],

swc: () => ({
jsc: {
transform: {
react: {
runtime: 'automatic',
},
framework: {
name: '@storybook/react-vite',
options: {
builder: {
viteConfigPath: 'vite.storybook.config.ts',
},
},
}),

webpackFinal(config) {
return {
...config,

resolve: {
...config.resolve,
alias: {
...config.resolve?.alias,
// Custom path aliases. Keep in sync with `paths` in tsconfig.json.
'~': path.resolve(__dirname, '../app'),
tests: path.resolve(__dirname, '../tests'),
},
fallback: {
...config.resolve?.fallback,
// Suppress un-polyfilled module warning from @sinonjs/fake-timers.
timers: false,
},
},

module: {
...config.module,
rules: [
...(config.module?.rules || []),
// Replace @remix-run/node with an empty file. It should never be used by browser code.
{
test: require.resolve('@remix-run/node'),
use: 'null-loader',
},
// Replace `.server.ts` files with an empty file. Remix will never send these to the
// browser.
{
test: /\.server/,
use: 'null-loader',
},
// Integrate Tailwind. Remix handles this when running the app, but we need to configure it
// ourselves in Storybook.
{
test: /\.css$/i,
use: ['postcss-loader'],
},
],
},
};
},
core: {
disableTelemetry: true,
},
addons: ['@storybook/addon-a11y', '@storybook/addon-essentials'],
} satisfies StorybookConfig;
Loading

0 comments on commit 694d4c6

Please sign in to comment.