|
| 1 | +/* eslint-disable no-console */ |
1 | 2 | import type { Rollup, Plugin, ViteDevServer, HmrContext } from 'vite';
|
2 | 3 | import { hashCode } from '../../../core/util/hash_code';
|
3 | 4 | import { generateManifestFromBundles, getValidManifest } from '../manifest';
|
@@ -877,34 +878,19 @@ export const manifest = ${JSON.stringify(manifest)};\n`;
|
877 | 878 | const module = getModuleInfo(id)!;
|
878 | 879 | const segment = module.meta.segment;
|
879 | 880 |
|
| 881 | + // We need to specifically return segment.entry for qwik-insights |
880 | 882 | if (segment) {
|
881 |
| - // We need to specifically return segment.entry for qwik-insights |
882 | 883 | return segment.entry;
|
883 | 884 | }
|
884 | 885 |
|
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. |
901 | 886 | if (id.includes('node_modules')) {
|
902 | 887 | return null;
|
903 | 888 | }
|
904 | 889 |
|
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)) { |
908 | 894 | const optimizer = getOptimizer();
|
909 | 895 | const path = optimizer.sys.path;
|
910 | 896 | const relativePath = path.relative(optimizer.sys.cwd(), id);
|
|
0 commit comments