Skip to content

Commit 1f5e4ea

Browse files
committed
perf(qwikcity): remove qwikcity plan dyn imports from bundlegraph
1 parent ea509f0 commit 1f5e4ea

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

packages/qwik-city/src/buildtime/vite/get-route-imports.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { QwikBundle, QwikManifest } from '@builder.io/qwik/optimizer';
22
import { removeExtension } from '../../utils/fs';
33
import type { BuildRoute } from '../types';
4+
import { QWIK_CITY_PLAN_ID } from './plugin';
45

56
export function getRouteImports(routes: BuildRoute[], manifest: QwikManifest) {
6-
const result: Record<string, { imports?: string[] }> = {};
7+
const result: Record<string, { imports?: string[]; dynamicImports?: string[] }> = {};
78
routes.forEach((route) => {
89
const routePath = removeExtension(route.filePath);
910
const layoutPaths = route.layouts
@@ -22,6 +23,15 @@ export function getRouteImports(routes: BuildRoute[], manifest: QwikManifest) {
2223
result[route.routeName] = { imports };
2324
}
2425
});
26+
for (const bundleName of Object.keys(manifest.bundles)) {
27+
const bundle = manifest.bundles[bundleName];
28+
if (bundle.origins?.some((s) => s.endsWith(QWIK_CITY_PLAN_ID))) {
29+
// Don't consider the city plan for preloading
30+
// we keep imports because something might be bundled with it
31+
result[bundleName] = { imports: bundle.imports, dynamicImports: [] };
32+
break;
33+
}
34+
}
2535
return result;
2636
}
2737

packages/qwik-city/src/buildtime/vite/get-route-imports.unit.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ describe('modifyBundleGraph', () => {
2929
size: 0,
3030
origins: ['src/routes/layout.tsx'],
3131
},
32+
'q-city-plan.js': {
33+
size: 0,
34+
origins: ['@qwik-city-plan'],
35+
},
3236
} as Record<string, QwikBundle>,
3337
} as QwikManifest;
3438

@@ -62,6 +66,10 @@ describe('modifyBundleGraph', () => {
6266
"fake-bundle-part-of-layout.js",
6367
],
6468
},
69+
"q-city-plan.js": {
70+
"dynamicImports": [],
71+
"imports": undefined,
72+
},
6573
}
6674
`);
6775
});

packages/qwik-city/src/buildtime/vite/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function qwikCityPlugin(userOpts?: QwikCityVitePluginOptions): any {
315315
}
316316

317317
const QWIK_SERIALIZER = '@qwik-serializer';
318-
const QWIK_CITY_PLAN_ID = '@qwik-city-plan';
318+
export const QWIK_CITY_PLAN_ID = '@qwik-city-plan';
319319
const QWIK_CITY_ENTRIES_ID = '@qwik-city-entries';
320320
const QWIK_CITY = '@builder.io/qwik-city';
321321
const QWIK_CITY_SW_REGISTER = '@qwik-city-sw-register';

packages/qwik/src/optimizer/src/plugins/bundle-graph.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ export function convertManifestToBundleGraph(
112112
for (const depName of dynDeps) {
113113
clearTransitiveDeps(dynDeps, depName);
114114
}
115-
// If we have a lot of dynamic imports, we don't know which ones are needed, so we don't add any
116-
// This can happen with registry bundles like for routing
117-
if (dynDeps.size > 0 && dynDeps.size < 10) {
115+
if (dynDeps.size > 0) {
116+
// We rely on the Set keeping the items in order, everything after this is dynamic
118117
deps.add(dynamicTag);
119118
for (const depName of dynDeps) {
120119
deps.add(depName);

0 commit comments

Comments
 (0)