1 | import { BaseLoader } from "./loader"
|
2 | import { findPath } from "./find-path"
|
3 |
|
4 | class 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 |
|
23 |
|
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 |
|
39 | export default DevLoader
|