2019-04-24 16:47:50 +02:00
|
|
|
|
import {BUILD_MANIFEST, CLIENT_STATIC_FILES_PATH, REACT_LOADABLE_MANIFEST, SERVER_DIRECTORY} from '../lib/constants';
|
2019-03-19 04:24:21 +01:00
|
|
|
|
import { join } from 'path';
|
|
|
|
|
|
2019-04-11 20:59:26 +02:00
|
|
|
|
import { requirePage } from './require';
|
2018-12-18 17:12:49 +01:00
|
|
|
|
|
2019-05-11 13:18:56 +02:00
|
|
|
|
export function interopDefault(mod: any) {
|
2018-12-18 17:12:49 +01:00
|
|
|
|
return mod.default || mod
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 20:59:26 +02:00
|
|
|
|
export async function loadComponents(distDir: string, buildId: string, pathname: string) {
|
2018-12-18 17:12:49 +01: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')
|
2019-03-19 04:24:21 +01:00
|
|
|
|
|
2019-04-11 20:59:26 +02:00
|
|
|
|
const [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([
|
2018-12-18 17:12:49 +01:00
|
|
|
|
require(join(distDir, BUILD_MANIFEST)),
|
|
|
|
|
require(join(distDir, REACT_LOADABLE_MANIFEST)),
|
2019-04-11 20:59:26 +02:00
|
|
|
|
interopDefault(requirePage(pathname, distDir)),
|
2018-12-18 17:12:49 +01:00
|
|
|
|
interopDefault(require(documentPath)),
|
2018-12-31 14:44:27 +01:00
|
|
|
|
interopDefault(require(appPath)),
|
2018-12-18 17:12:49 +01:00
|
|
|
|
])
|
|
|
|
|
|
2019-04-11 20:59:26 +02:00
|
|
|
|
return {buildManifest, reactLoadableManifest, Component, Document, App}
|
2018-12-18 17:12:49 +01:00
|
|
|
|
}
|