Skip to content

Commit b3d0932

Browse files
authored
Merge pull request #32881 from storybookjs/norbert/improve-optimizedeps-array
Vite: Update `optimizeViteDeps` for addon-docs and addon-vitest
2 parents 1342fd5 + 02609c1 commit b3d0932

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

code/addons/docs/src/preset.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ export const resolvedReact = async (existing: any) => ({
205205
});
206206

207207
const optimizeViteDeps = [
208-
'@mdx-js/react',
209208
'@storybook/addon-docs',
210209
'@storybook/addon-docs/blocks',
211-
'markdown-to-jsx',
210+
'@storybook/addon-docs > @mdx-js/react',
212211
];
213212

214213
export { webpackX as webpack, docsX as docs, optimizeViteDeps };

code/builders/builder-vite/src/optimizeDeps.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { listStories } from './list-stories';
1414
const asyncFilter = async (arr: string[], predicate: (val: string) => Promise<boolean>) =>
1515
Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));
1616

17+
// TODO: This function should be reworked. The code it uses is outdated and we need to investigate
18+
// More info: https://github.com/storybookjs/storybook/issues/32462#issuecomment-3421326557
1719
export async function getOptimizeDeps(config: ViteInlineConfig, options: Options) {
1820
const extraOptimizeDeps = await options.presets.apply('optimizeViteDeps', []);
1921

@@ -27,18 +29,15 @@ export async function getOptimizeDeps(config: ViteInlineConfig, options: Options
2729
// This function converts ids which might include ` > ` to a real path, if it exists on disk.
2830
// See https://github.com/vitejs/vite/blob/67d164392e8e9081dc3f0338c4b4b8eea6c5f7da/packages/vite/src/node/optimizer/index.ts#L182-L199
2931
const resolve = resolvedConfig.createResolver({ asSrc: false });
30-
const include = await asyncFilter(
31-
Array.from(new Set([...INCLUDE_CANDIDATES, ...extraOptimizeDeps])),
32-
async (id) => Boolean(await resolve(id))
33-
);
32+
const include = await asyncFilter(INCLUDE_CANDIDATES, async (id) => Boolean(await resolve(id)));
3433

3534
const optimizeDeps: UserConfig['optimizeDeps'] = {
3635
...config.optimizeDeps,
3736
// We don't need to resolve the glob since vite supports globs for entries.
3837
entries: stories,
3938
// We need Vite to precompile these dependencies, because they contain non-ESM code that would break
4039
// if we served it directly to the browser.
41-
include: [...include, ...(config.optimizeDeps?.include || [])],
40+
include: [...include, ...extraOptimizeDeps, ...(config.optimizeDeps?.include || [])],
4241
};
4342

4443
return optimizeDeps;

0 commit comments

Comments
 (0)