Back to Storybook

Msw Addon Initialize

docs/_snippets/msw-addon-initialize.md

10.5.54.1 KB
Original Source
js
import { mswLoader } from 'msw-storybook-addon/csf3';

export default {
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-30
   * to learn how to customize it
   */
  loaders: [mswLoader()],
};
ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { Preview } from '@storybook/your-framework';

import { mswLoader } from 'msw-storybook-addon/csf3';

const preview: Preview = {
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-30
   * to learn how to customize it
   */
  loaders: [mswLoader()],
};

export default preview;
ts
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { definePreview } from '@storybook/your-framework';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { definePreview } from '@storybook/your-framework';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});
ts
import { definePreview } from '@storybook/vue3-vite';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});
js
import { definePreview } from '@storybook/vue3-vite';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});
ts
import { definePreview } from '@storybook/angular';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});
ts
import { definePreview } from '@storybook/web-components-vite';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import { definePreview } from '@storybook/web-components-vite';

import addonMsw from 'msw-storybook-addon';

export default definePreview({
  /*
   * Register the MSW loader for all stories
   * See https://github.com/mswjs/msw-storybook-addon#csf-next
   * to learn how to customize it
   */
  addons: [addonMsw()],
});