UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

68 lines (67 loc) 2.95 kB
export { analyzePage }; import { getVikeClientEntry } from '../../../shared/getPageFiles/analyzePageClientSide/determineClientEntry.js'; import { analyzePageClientSide } from '../../../shared/getPageFiles/analyzePageClientSide.js'; import { getVirtualFileIdPageConfigLazy } from '../../shared/virtualFiles/virtualFilePageConfigLazy.js'; import { analyzeClientSide } from '../../../shared/getPageFiles/analyzeClientSide.js'; import { getConfigValueRuntime } from '../../../shared/page-configs/getConfigValueRuntime.js'; async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) { if (pageConfig) { const { isClientRuntimeLoaded, isClientRouting } = analyzeClientSide(pageConfig, pageFilesAll, pageId); const clientEntries = []; const clientFilePath = getConfigValueRuntime(pageConfig, 'client', 'string')?.value ?? null; if (clientFilePath) clientEntries.push(clientFilePath); if (isClientRuntimeLoaded) clientEntries.push(getVikeClientEntry(isClientRouting)); const clientDependencies = []; clientDependencies.push({ id: getVirtualFileIdPageConfigLazy(pageConfig.pageId, true), onlyAssets: isClientRuntimeLoaded ? false : true, eagerlyImported: false, }); // In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module if (!globalContext._isProduction) { clientDependencies.push({ id: getVirtualFileIdPageConfigLazy(pageConfig.pageId, false), onlyAssets: true, eagerlyImported: false, }); } /* Remove? Object.values(pageConfig.configElements).forEach((configElement) => { if (configElement.importPath) { const { env } = configElement assert(env) const onlyAssets = env === { server: true } const eagerlyImported = env === { server: true, client: 'if-client-routing', eager: true } if (onlyAssets || eagerlyImported) { clientDependencies.push({ id: configElement.importPath, onlyAssets, eagerlyImported }) } } }) */ clientEntries.forEach((clientEntry) => { clientDependencies.push({ id: clientEntry, onlyAssets: false, eagerlyImported: false, }); }); return { isHtmlOnly: !isClientRuntimeLoaded, isClientRouting, clientEntries, clientDependencies, // pageFilesClientSide and pageFilesServerSide are only used for debugging pageFilesClientSide: [], pageFilesServerSide: [], }; } else { return analyzePageClientSide(pageFilesAll, pageId); } }