Add template to wp5 builder

This commit is contained in:
Tom Coleman 2021-09-04 11:47:12 +10:00
parent d28587dc09
commit c9e8fc3b8b

View File

@ -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 });
});
}