Skip to content

Commit df777a8

Browse files
committed
fix(rollup): prevent over-prefetching
1 parent f3aec78 commit df777a8

File tree

1 file changed

+32
-2
lines changed
  • packages/qwik/src/optimizer/src/plugins

1 file changed

+32
-2
lines changed

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,38 @@ export const manifest = ${JSON.stringify(manifest)};\n`;
875875
// order by discovery time, so that related segments are more likely to group together
876876
function manualChunks(id: string, { getModuleInfo }: Rollup.ManualChunkMeta) {
877877
const module = getModuleInfo(id)!;
878-
const segment = module.meta.segment as SegmentAnalysis | undefined;
879-
return segment?.entry;
878+
const segment = module.meta.segment;
879+
880+
const optimizer = getOptimizer();
881+
const path = optimizer.sys.path;
882+
const relativePath = path.relative(optimizer.sys.cwd(), id);
883+
const sanitizedPath = relativePath.replace(/^\/+/, '').replace(/\//g, '-');
884+
885+
if (sanitizedPath.includes('node_modules')) {
886+
if (sanitizedPath.includes('core.prod')) {
887+
return 'core';
888+
}
889+
return null;
890+
}
891+
892+
if (sanitizedPath.includes('preload-helper')) {
893+
return 'preload-helper';
894+
}
895+
896+
if (
897+
segment ||
898+
sanitizedPath.endsWith('.qwik.mjs') ||
899+
sanitizedPath.endsWith('.qwik.cjs') ||
900+
sanitizedPath.endsWith('.tsx') ||
901+
sanitizedPath.endsWith('.jsx') ||
902+
sanitizedPath.endsWith('.mdx') ||
903+
sanitizedPath.endsWith('.ts') ||
904+
sanitizedPath.endsWith('.js')
905+
) {
906+
return sanitizedPath;
907+
}
908+
909+
return null;
880910
}
881911

882912
return {

0 commit comments

Comments
 (0)