UNPKG

1.05 kBJavaScriptView Raw
1import { BaseLoader } from "./loader"
2import { findPath } from "./find-path"
3
4class DevLoader extends BaseLoader {
5 constructor(syncRequires, matchPaths) {
6 const loadComponent = chunkName =>
7 Promise.resolve(syncRequires.components[chunkName])
8 super(loadComponent, matchPaths)
9 }
10
11 loadPage(pagePath) {
12 const realPath = findPath(pagePath)
13 return super.loadPage(realPath).then(result =>
14 require(`./socketIo`)
15 .getPageData(realPath)
16 .then(() => result)
17 )
18 }
19
20 loadPageDataJson(rawPath) {
21 return super.loadPageDataJson(rawPath).then(data => {
22 // when we can't find a proper 404.html we fallback to dev-404-page
23 // we need to make sure to mark it as not found.
24 if (data.status === `failure`) {
25 return this.loadPageDataJson(`/dev-404-page/`).then(result =>
26 Object.assign({}, data, result)
27 )
28 }
29
30 return data
31 })
32 }
33
34 doPrefetch(pagePath) {
35 return Promise.resolve(require(`./socketIo`).getPageData(pagePath))
36 }
37}
38
39export default DevLoader