Skip to content

Commit daf2ca8

Browse files
authored
Merge pull request #2675 from modernweb-dev/fix/storybook-builder-tocbot-default
fix(storybook-builder): fix tocbot default import by @storybook/blocks
2 parents 0b8390f + 331e621 commit daf2ca8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/four-scissors-greet.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/storybook-builder': patch
3+
---
4+
5+
fix tocbot default import by @storybook/blocks

packages/storybook-builder/src/esbuild-plugin-commonjs-named-exports.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export function esbuildPluginCommonjsNamedExports(module: string, namedExports:
1919
contents: `
2020
import { default as commonjsExports } from '${module}?force-original';
2121
${namedExports
22-
.map(name => `export const ${name} = commonjsExports.${name};`)
22+
.map(name => {
23+
if (name === 'default') {
24+
return `export default commonjsExports;`;
25+
} else {
26+
return `export const ${name} = commonjsExports.${name};`;
27+
}
28+
})
2329
.join('\n')}
2430
`,
2531
};

packages/storybook-builder/src/rollup-plugin-prebundle-modules.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function rollupPluginPrebundleModules(env: Record<string, string>): Plugi
5050
/* for @storybook/addon-docs */
5151
// tocbot can't be automatically transformed by @chialab/esbuild-plugin-commonjs
5252
// so we need a manual wrapper
53-
esbuildPluginCommonjsNamedExports('tocbot', ['init', 'destroy']),
53+
esbuildPluginCommonjsNamedExports('tocbot', ['default', 'init', 'destroy']),
5454

5555
esbuildPluginCommonjs(),
5656
],

0 commit comments

Comments
 (0)