virtualModuleModernEntry.js.handlebars 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { global } from '@storybook/global';
  2. import { ClientApi, PreviewWeb, addons, composeConfigs } from '@storybook/preview-api';
  3. import { createBrowserChannel } from '@storybook/channels';
  4. import { importFn } from './{{storiesFilename}}';
  5. const getProjectAnnotations = () =>
  6. composeConfigs([{{#each previewAnnotations}}require('{{this}}'),{{/each}}]);
  7. const channel = createBrowserChannel({ page: 'preview' });
  8. addons.setChannel(channel);
  9. if (global.CONFIG_TYPE === 'DEVELOPMENT'){
  10. window.__STORYBOOK_SERVER_CHANNEL__ = channel;
  11. }
  12. const preview = new PreviewWeb();
  13. window.__STORYBOOK_PREVIEW__ = preview;
  14. window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
  15. window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
  16. window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore });
  17. preview.initialize({ importFn, getProjectAnnotations });
  18. if (import.meta.webpackHot) {
  19. import.meta.webpackHot.accept('./{{storiesFilename}}', () => {
  20. // importFn has changed so we need to patch the new one in
  21. preview.onStoriesChanged({ importFn });
  22. });
  23. import.meta.webpackHot.accept([{{#each previewAnnotations}}'{{this}}',{{/each}}], () => {
  24. // getProjectAnnotations has changed so we need to patch the new one in
  25. preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
  26. });
  27. }