Skip to content

Commit b05fba4

Browse files
committed
externalize candidatesm solve jsx-runtim and minimize bundling
1 parent a74d507 commit b05fba4

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export function esbuildPluginCommonjsNamedExports(modules: string[]): Plugin {
1515
if (args.pluginData?.preventInfiniteRecursion) return;
1616

1717
const { path, ...rest } = args;
18+
rest.kind = 'entry-point'; // forces resolution to the file path, because we need names for external modules too
19+
rest.importer = '';
20+
rest.namespace = '';
1821
rest.pluginData = { preventInfiniteRecursion: true };
1922
const resolveResult = await build.resolve(path, rest);
2023
const resolvedPath = resolveResult.path;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function rollupPluginPrebundleModules(env: Record<string, string>): Plugi
4545
'@storybook/react-dom-shim': await getReactDomShimAlias(),
4646
}),
4747
},
48-
// TODO(storybook): mark React module as external to prevent bundling and duplicates in runtime
48+
external: [...modules],
4949
define: (() => {
5050
const define = stringifyProcessEnvs(env);
5151

@@ -72,14 +72,13 @@ export function rollupPluginPrebundleModules(env: Record<string, string>): Plugi
7272
// we aim only at browserifying NodeJS dependencies (CommonJS/process.env/...)
7373
export const CANDIDATES = [
7474
/* for different addons built with React and for MDX */
75-
'@storybook/react-dom-shim', // needs special resolution
7675
'react',
77-
process.env.NODE_ENV === 'production' ? 'react/jsx-runtime' : 'react/jsx-dev-runtime',
76+
'react/jsx-runtime',
77+
'react/jsx-dev-runtime',
7878
'react-dom',
79+
'react-dom/client',
7980

8081
/* for different packages */
81-
'@storybook/components',
82-
'@storybook/test',
8382
'memoizerific',
8483
'tiny-invariant',
8584

packages/storybook-framework-web-components/tests/fixtures/all-in-one/.storybook/main.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ const config = {
2323
return;
2424
}
2525

26-
// ignore warning about eval which comes from bundled telejson
26+
// ignore warning about eval used by the storybook internals
2727
if (log.code === 'EVAL') {
2828
const logId = log.id?.replace(/\\/g, '/');
29-
if (
30-
// TODO(storybook): looks like '@storybook/test' bundles too much, including the "@storybook/core"
31-
// TODO(storybook): exact eval seems to be from get-intrinsic, not from telejson which is weird given telejson is still used
32-
logId?.includes('node_modules/.prebundled_modules/@storybook/test.mjs') ||
33-
logId?.includes('node_modules/@storybook/core/dist/preview/runtime.js')
34-
) {
29+
if (logId?.includes('node_modules/@storybook/core/dist/preview/runtime.js')) {
3530
defaultHandler('warn', log);
3631
return;
3732
}

0 commit comments

Comments
 (0)