Skip to content

Commit

Permalink
Add pages pre-import
Browse files Browse the repository at this point in the history
  • Loading branch information
gwer committed Mar 18, 2021
1 parent ea374d8 commit 658eb91
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs'
import chalk from 'chalk'
import { IncomingMessage, ServerResponse } from 'http'
import Proxy from 'next/dist/compiled/http-proxy'
import { join, relative, resolve, sep } from 'path'
import { join, relative, resolve, sep, extname } from 'path'
import {
parse as parseQs,
stringify as stringifyQs,
Expand Down Expand Up @@ -242,6 +242,17 @@ export default class Server {
this.pagesManifest = require(pagesManifestPath)
}

// Pages pre-import speed up initial pages render
if (this.pagesManifest) {
Object.values(this.pagesManifest).forEach((pageModule) => {
if (extname(pageModule) !== '.js') {
return
}

require(join(this.serverBuildDir, pageModule))
})
}

this.customRoutes = this.getCustomRoutes()
this.router = new Router(this.generateRoutes())
this.setAssetPrefix(assetPrefix)
Expand Down

0 comments on commit 658eb91

Please sign in to comment.