1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Load the hot-reloader when only needed. (#2566)

This reduce the server boot-up time a lot.
With a 2015 MacBook Pro, it went down from 1000ms to 200ms
This commit is contained in:
Arunoda Susiripala 2017-07-15 15:59:10 +05:30 committed by Guillermo Rauch
parent 20db38e21a
commit f25055c9f7

View file

@ -12,7 +12,6 @@ import {
renderScriptError renderScriptError
} from './render' } from './render'
import Router from './router' import Router from './router'
import HotReloader from './hot-reloader'
import { resolveFromList } from './resolve' import { resolveFromList } from './resolve'
import { getAvailableChunks } from './utils' import { getAvailableChunks } from './utils'
import getConfig from './config' import getConfig from './config'
@ -35,7 +34,7 @@ export default class Server {
this.dev = dev this.dev = dev
this.quiet = quiet this.quiet = quiet
this.router = new Router() this.router = new Router()
this.hotReloader = dev ? new HotReloader(this.dir, { quiet, conf }) : null this.hotReloader = dev ? this.getHotReloader(this.dir, { quiet, conf }) : null
this.http = null this.http = null
this.config = getConfig(this.dir, conf) this.config = getConfig(this.dir, conf)
this.dist = this.config.distDir this.dist = this.config.distDir
@ -59,6 +58,11 @@ export default class Server {
this.defineRoutes() this.defineRoutes()
} }
getHotReloader (dir, options) {
const HotReloader = require('./hot-reloader').default
return new HotReloader(dir, options)
}
handleRequest (req, res, parsedUrl) { handleRequest (req, res, parsedUrl) {
// Parse url if parsedUrl not provided // Parse url if parsedUrl not provided
if (!parsedUrl || typeof parsedUrl !== 'object') { if (!parsedUrl || typeof parsedUrl !== 'object') {