-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathvirtualModuleModernEntry.js.handlebars
39 lines (30 loc) · 1.22 KB
/
virtualModuleModernEntry.js.handlebars
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fetch from 'unfetch';
import { composeConfigs, PreviewWeb } from '@storybook/preview-web';
import { ClientApi } from '@storybook/client-api';
import { addons } from '@storybook/addons';
import createChannel from '@storybook/channel-postmessage';
import { importFn } from './{{storiesFilename}}';
const getProjectAnnotations = () =>
composeConfigs([
{{#each configs}}
require('{{this}}'),
{{/each}}
]);
const channel = createChannel({ page: 'preview' });
addons.setChannel(channel);
const preview = new PreviewWeb();
window.__STORYBOOK_PREVIEW__ = preview;
window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
window.__STORYBOOK_CLIENT_API__ = new ClientApi({ storyStore: preview.storyStore });
preview.initialize({ importFn, getProjectAnnotations });
if (module.hot) {
module.hot.accept('./{{storiesFilename}}', () => {
// importFn has changed so we need to patch the new one in
preview.onStoriesChanged({ importFn });
});
module.hot.accept([{{#each configs}}'{{this}}',{{/each}}], () => {
// getProjectAnnotations has changed so we need to patch the new one in
preview.onGetProjectAnnotationsChanged({ getProjectAnnotations });
});
}