Skip to content

Commit 96b533a

Browse files
authored
Merge pull request #7370 from maiieul/fix-repl
fix(docs repl): let rollup handle more chunks
2 parents 5e2a83a + 9b524b1 commit 96b533a

File tree

1 file changed

+6
-20
lines changed
  • packages/qwik/src/optimizer/src/plugins

1 file changed

+6
-20
lines changed

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import type { Rollup, Plugin, ViteDevServer, HmrContext } from 'vite';
23
import { hashCode } from '../../../core/util/hash_code';
34
import { generateManifestFromBundles, getValidManifest } from '../manifest';
@@ -877,34 +878,19 @@ export const manifest = ${JSON.stringify(manifest)};\n`;
877878
const module = getModuleInfo(id)!;
878879
const segment = module.meta.segment;
879880

881+
// We need to specifically return segment.entry for qwik-insights
880882
if (segment) {
881-
// We need to specifically return segment.entry for qwik-insights
882883
return segment.entry;
883884
}
884885

885-
// To prevent over-prefetching, we need to clearly seperate those chunks,
886-
// otherwise rollup can bundle them together with the first component chunk it finds.
887-
// For example, the core code could go into an Accordion.tsx chunk, which would make the whole app import accordion related chunks everywhere.
888-
if (/\/(qwik|core)\/dist\/core.*js$/.test(id) || id.includes('@builder.io/qwik/build')) {
889-
return 'core';
890-
}
891-
if (/\/(qwik-city|router)\/lib\/index.qwik.*js$/.test(id)) {
892-
return 'qwik-city';
893-
}
894-
if (id.endsWith('vite/preload-helper.js')) {
895-
return 'preload-helper';
896-
}
897-
898-
// We can't return a chunk for each module as that creates too many small chunks that slow down the prefetching as well,
899-
// nor can we bundle related node_modules together (e.g. all shiki modules together), as that can create very big 10MB chunks.
900-
// So here we let rollup do its job.
901886
if (id.includes('node_modules')) {
902887
return null;
903888
}
904889

905-
// Also to prevent over-prefetching, we must clearly separate those chunks so that rollup doesn't add additional imports into entry files.
906-
// We do this after the node_modules check, because some node_modules can end with .js, .ts, etc.
907-
if (/\.(qwik\.mjs|qwik\.cjs|tsx|jsx|mdx|ts|js)$/.test(id)) {
890+
// Patch to prevent over-prefetching, we must clearly separate .tsx/.jsx chunks so that rollup doesn't mix random imports into non-entry files such as hooks.
891+
// Maybe a better solution would be to mark those files as entires earlier in the chain so that we can remove this check and the one above altogether.
892+
// We check .(tsx|jsx) after node_modules in case some node_modules end with .jsx or .tsx.
893+
if (/\.(tsx|jsx)$/.test(id)) {
908894
const optimizer = getOptimizer();
909895
const path = optimizer.sys.path;
910896
const relativePath = path.relative(optimizer.sys.cwd(), id);

0 commit comments

Comments
 (0)