diff --git a/vike/node/runtime/globalContext.ts b/vike/node/runtime/globalContext.ts index 0705c040906..aa5f711b91b 100644 --- a/vike/node/runtime/globalContext.ts +++ b/vike/node/runtime/globalContext.ts @@ -31,6 +31,7 @@ import type { ConfigVikeResolved } from '../../shared/ConfigVike.js' import { getConfigVike } from '../shared/getConfigVike.js' import { assertRuntimeManifest, type RuntimeManifest } from '../shared/assertRuntimeManifest.js' import pc from '@brillout/picocolors' +import { getPageFilesExports } from './page-files/getPageFilesExports.js' let resolveGlobalContext: (globalContext: GlobalContext) => void const globalObject = getGlobalObject<{ globalContext?: GlobalContext @@ -133,6 +134,7 @@ function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer) { assert(!globalObject.globalContext) globalObject.viteConfig = viteDevServer.config globalObject.viteDevServer = viteDevServer + eagerlyLoadUserFiles() } function setGlobalContext_isDev(isDev: boolean) { globalObject.isDev = isDev @@ -253,3 +255,9 @@ function assertViteManifest(manifest: unknown): asserts manifest is ViteManifest }) */ } + +function eagerlyLoadUserFiles() { + // Other than here, the getPageFilesExports() function is only called only upon calling the renderPage() function. + // We call it as early as possible here for better performance. + getPageFilesExports() +}