UNPKG

@web/storybook-builder

Version:
45 lines (40 loc) 2.16 kB
"use strict"; // based on https://github.com/storybookjs/storybook/blob/v8.5.0/code/builders/builder-vite/src/codegen-modern-iframe-script.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.generateAppScript = void 0; const pluginutils_1 = require("@rollup/pluginutils"); const core_common_1 = require("@storybook/core-common"); const virtual_file_names_js_1 = require("./virtual-file-names.js"); async function generateAppScript(options) { const { presets, configDir } = options; const previewOrConfigFile = (0, core_common_1.loadPreviewOrConfigFile)({ configDir }); const previewAnnotations = await presets.apply('previewAnnotations', [], options); const previewAnnotationURLs = [...previewAnnotations, previewOrConfigFile] .filter((path) => !!path) .map((path) => (typeof path === 'object' ? path.bare : path)); // This is pulled out to a variable because it is reused in both the initial page load // and the HMR handler. We don't use the hot.accept callback params because only the changed // modules are provided, the rest are null. We can just re-import everything again in that case. const getPreviewAnnotationsFunction = ` const getProjectAnnotations = async () => { const configs = await Promise.all([ ${previewAnnotationURLs .map(previewAnnotation => ` import('${(0, pluginutils_1.normalizePath)(previewAnnotation)}')`) .join(',\n')} ]); return composeConfigs(configs); } `.trim(); return ` import { setup } from '@storybook/core/preview/runtime'; import '${virtual_file_names_js_1.virtualSetupAddonsFilename}'; setup(); import { composeConfigs, PreviewWeb, ClientApi } from '@storybook/preview-api'; import { importFn } from '${virtual_file_names_js_1.virtualStoriesFilename}'; ${getPreviewAnnotationsFunction} window.__STORYBOOK_PREVIEW__ = window.__STORYBOOK_PREVIEW__ || new PreviewWeb(importFn, getProjectAnnotations); window.__STORYBOOK_STORY_STORE__ = window.__STORYBOOK_STORY_STORE__ || window.__STORYBOOK_PREVIEW__.storyStore; `.trim(); } exports.generateAppScript = generateAppScript; //# sourceMappingURL=generate-app-script.js.map