2018-12-18 16:12:49 +00:00
|
|
|
import {join} from 'path'
|
|
|
|
import {CLIENT_STATIC_FILES_PATH, BUILD_MANIFEST, REACT_LOADABLE_MANIFEST, SERVER_DIRECTORY} from 'next-server/constants'
|
|
|
|
import {requirePage} from './require'
|
|
|
|
|
2018-12-31 13:44:27 +00:00
|
|
|
function interopDefault(mod: any) {
|
2018-12-18 16:12:49 +00:00
|
|
|
return mod.default || mod
|
|
|
|
}
|
|
|
|
|
2018-12-31 13:44:27 +00:00
|
|
|
export async function loadComponents(distDir: string, buildId: string, pathname: string) {
|
2018-12-18 16:12:49 +00:00
|
|
|
const documentPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_document')
|
|
|
|
const appPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_app')
|
2018-12-31 13:44:27 +00:00
|
|
|
const [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([
|
2018-12-18 16:12:49 +00:00
|
|
|
require(join(distDir, BUILD_MANIFEST)),
|
|
|
|
require(join(distDir, REACT_LOADABLE_MANIFEST)),
|
|
|
|
interopDefault(requirePage(pathname, distDir)),
|
|
|
|
interopDefault(require(documentPath)),
|
2018-12-31 13:44:27 +00:00
|
|
|
interopDefault(require(appPath)),
|
2018-12-18 16:12:49 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
return {buildManifest, reactLoadableManifest, Component, Document, App}
|
|
|
|
}
|