mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Add template to wp5 builder
This commit is contained in:
parent
d28587dc09
commit
c9e8fc3b8b
@ -0,0 +1,43 @@
|
||||
import { composeConfigs, WebPreview } from '@storybook/web-preview';
|
||||
import { importFn } from './{{storiesFilename}}';
|
||||
import { addons } from '@storybook/addons';
|
||||
import createChannel from '@storybook/channel-postmessage';
|
||||
import fetch from 'unfetch';
|
||||
|
||||
const getGlobalAnnotations = () =>
|
||||
composeConfigs([
|
||||
{{#each configs}}
|
||||
require('{{this}}'),
|
||||
{{/each}}
|
||||
]);
|
||||
|
||||
const fetchStoriesList = async () => {
|
||||
const result = await fetch('./stories.json');
|
||||
return result.json();
|
||||
}
|
||||
|
||||
const channel = createChannel({ page: 'preview' });
|
||||
addons.setChannel(channel);
|
||||
const preview = new WebPreview({ importFn, getGlobalAnnotations, fetchStoriesList });
|
||||
|
||||
window.__STORYBOOK_PREVIEW__ = preview;
|
||||
window.__STORYBOOK_STORY_STORE__ = preview.storyStore;
|
||||
window.__STORYBOOK_ADDONS_CHANNEL__ = channel;
|
||||
|
||||
preview.initialize();
|
||||
|
||||
if (module.hot) {
|
||||
module.hot.accept('./{{storiesFilename}}', () => {
|
||||
console.log('configEntry HMR accept storybook-stories.js');
|
||||
console.log(arguments);
|
||||
// importFn has changed so we need to patch the new one in
|
||||
preview.onImportFnChanged({ importFn });
|
||||
});
|
||||
|
||||
module.hot.accept([{{#each configs}}'{{this}}',{{/each}}], () => {
|
||||
console.log('configEntry HMR accept config file');
|
||||
console.log(arguments);
|
||||
// getGlobalAnnotations has changed so we need to patch the new one in
|
||||
preview.onGetGlobalAnnotationsChanged({ getGlobalAnnotations });
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user