-
-
Notifications
You must be signed in to change notification settings - Fork 330
/
analyzePage.ts
70 lines (68 loc) 路 2.91 KB
/
analyzePage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
export { analyzePage }
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js'
import { getVikeClientEntry } from '../../../shared/getPageFiles/analyzePageClientSide/determineClientEntry.js'
import type { PageFile } from '../../../shared/getPageFiles/getPageFileObject.js'
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js'
import { type AnalysisResult, analyzePageClientSide } from '../../../shared/getPageFiles/analyzePageClientSide.js'
import { getVirtualFileIdPageConfigValuesAll } from '../../shared/virtual-files/virtualFilePageConfigValuesAll.js'
import { analyzeClientSide } from '../../../shared/getPageFiles/analyzeClientSide.js'
import { getGlobalContext } from '../globalContext.js'
import { getClientEntry } from '../../shared/getClientEntry.js'
function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string): AnalysisResult {
if (pageConfig) {
const { isClientSideRenderable, isClientRouting } = analyzeClientSide(pageConfig, pageFilesAll, pageId)
const clientFilePath = getClientEntry(pageConfig)
const clientEntry = !isClientSideRenderable ? clientFilePath : getVikeClientEntry(isClientRouting)
const clientDependencies: ClientDependency[] = []
clientDependencies.push({
id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
onlyAssets: isClientSideRenderable ? false : true,
eagerlyImported: false
})
// In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
if (!getGlobalContext().isProduction) {
clientDependencies.push({
id: getVirtualFileIdPageConfigValuesAll(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
})
}
}
})
*/
const clientEntries: string[] = []
if (clientEntry) {
clientDependencies.push({
id: clientEntry,
onlyAssets: false,
eagerlyImported: false
})
clientEntries.push(clientEntry)
}
return {
isHtmlOnly: !isClientSideRenderable,
isClientRouting,
clientEntries,
clientDependencies,
// pageFilesClientSide and pageFilesServerSide are only used for debugging
pageFilesClientSide: [],
pageFilesServerSide: []
}
} else {
return analyzePageClientSide(pageFilesAll, pageId)
}
}