vike
Version:
(Replaces Next.js/Nuxt) 🔨 Composable framework to build advanced applications with flexibility and stability.
71 lines (70 loc) • 3.21 kB
JavaScript
export { analyzePage };
import { getVikeClientEntry } from '../../../shared-server-client/getPageFiles/analyzePageClientSide/determineClientEntry.js';
import { analyzePageClientSide, } from '../../../shared-server-client/getPageFiles/analyzePageClientSide.js';
import { generateVirtualFileId } from '../../../shared-server-node/virtualFileId.js';
import { analyzeClientSide } from '../../../shared-server-client/getPageFiles/analyzeClientSide.js';
import { getConfigValueRuntime } from '../../../shared-server-client/page-configs/getConfigValueRuntime.js';
import '../../assertEnvServer.js';
function analyzePage(pageContext) {
const { pageId, _pageConfig: pageConfig, _globalContext: globalContext } = pageContext;
const { _pageFilesAll: pageFilesAll } = 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: generateVirtualFileId({ type: 'page-entry', pageId: pageConfig.pageId, isForClientSide: 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: generateVirtualFileId({ type: 'page-entry', pageId: pageConfig.pageId, isForClientSide: 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);
}
}