Skip to content

Commit 594b54b

Browse files
committed
fix: storybook-vue/nuxt compat
1 parent 3d2877c commit 594b54b

File tree

3 files changed

+146
-69
lines changed

3 files changed

+146
-69
lines changed

.storybook/main.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,83 @@ const config = {
1111
async viteFinal(newConfig) {
1212
newConfig.plugins ??= []
1313

14+
// Bridge compatibility between Storybook v10 core and v9 @storybook-vue/nuxt
15+
// v10 expects module federation globals that v9 doesn't provide
16+
newConfig.plugins.push({
17+
name: 'storybook-v10-compat',
18+
transformIndexHtml: {
19+
order: 'pre',
20+
handler(html) {
21+
const script = `
22+
<script>
23+
// Minimal shims for Storybook v10 module federation system
24+
// These will be replaced by actual modules when Storybook runtime loads
25+
const noop = function() {};
26+
const noopLogger = { warn: noop, error: noop, info: noop, log: noop, debug: noop, trace: noop };
27+
28+
window.__STORYBOOK_MODULE_GLOBAL__ = { global: window };
29+
window.__STORYBOOK_MODULE_CLIENT_LOGGER__ = {
30+
deprecate: noop,
31+
once: noop,
32+
logger: noopLogger
33+
};
34+
window.__STORYBOOK_MODULE_CORE_EVENTS__ = {
35+
DOCS_PREPARED: 'docsPrepared',
36+
SET_STORIES: 'setStories',
37+
SHARED_STATE_CHANGED: 'sharedStateChanged',
38+
SHARED_STATE_SET: 'sharedStateSet',
39+
STORY_CHANGED: 'storyChanged',
40+
STORY_PREPARED: 'storyPrepared',
41+
SET_CONFIG: 'setConfig',
42+
GLOBALS_UPDATED: 'globalsUpdated',
43+
SET_GLOBALS: 'setGlobals',
44+
UPDATE_GLOBALS: 'updateGlobals'
45+
};
46+
window.__STORYBOOK_MODULE_CORE_EVENTS_PREVIEW_ERRORS__ = {};
47+
window.__STORYBOOK_MODULE_CHANNELS__ = {
48+
Channel: class Channel {
49+
on() {}
50+
off() {}
51+
emit() {}
52+
once() {}
53+
},
54+
createBrowserChannel: function() {
55+
return new window.__STORYBOOK_MODULE_CHANNELS__.Channel();
56+
}
57+
};
58+
window.__STORYBOOK_MODULE_PREVIEW_API__ = {
59+
addons: { getChannel: noop },
60+
useEffect: noop
61+
};
62+
window.__STORYBOOK_MODULE_TYPES__ = {
63+
Addon_TypesEnum: { PANEL: 'panel', TAB: 'tab', TOOL: 'tool', PREVIEW: 'preview' }
64+
};
65+
window.__STORYBOOK_MODULE_TEST__ = {
66+
onMockCall: noop,
67+
clearAllMocks: noop,
68+
fn: (impl) => impl || noop,
69+
isMockFunction: () => false,
70+
resetAllMocks: noop,
71+
restoreAllMocks: noop,
72+
uninstrumentedUserEvent: {},
73+
within: (canvas) => canvas,
74+
expect: (val) => ({
75+
toBe: noop,
76+
toEqual: noop,
77+
toBeTruthy: noop,
78+
toBeFalsy: noop,
79+
toHaveBeenCalled: noop,
80+
toHaveBeenCalledWith: noop
81+
})
82+
};
83+
window.__STORYBOOK_MODULE_ACTIONS__ = {};
84+
window.__STORYBOOK_MODULE_MOCK_SPIES__ = {};
85+
</script>`
86+
return html.replace(/<script>/, script + '<script>')
87+
},
88+
},
89+
})
90+
1491
newConfig.plugins.push({
1592
name: 'ignore-internals',
1693
transform(_, id) {

0 commit comments

Comments
 (0)