Skip to content

Commit

Permalink
perf: only require nextjs-require-cache-hot-reloader related API in d…
Browse files Browse the repository at this point in the history
…ev mode (#51834)

`nextjs-require-cache-hot-reloader` is only required in dev mode for plugin, we can skip these require in production mode

![image](https://github.com/vercel/next.js/assets/4800338/889f98db-7029-4aea-9d12-0e03547be606)
  • Loading branch information
huozhi committed Jun 27, 2023
1 parent 300507b commit d06bc5e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/next/src/server/lib/render-server.ts
Expand Up @@ -10,12 +10,8 @@ import '../require-hook'

import next from '../next'
import { warn } from '../../build/output/log'
import {
deleteCache as _deleteCache,
deleteAppClientCache as _deleteAppClientCache,
} from '../../build/webpack/plugins/nextjs-require-cache-hot-reloader'
import { clearModuleContext as _clearModuleContext } from '../web/sandbox/context'
import { getFreePort } from '../lib/worker-utils'

export const WORKER_SELF_EXIT_CODE = 77

const MAXIMUM_HEAP_SIZE_ALLOWED =
Expand All @@ -28,16 +24,26 @@ let result:
hostname: string
}

let sandboxContext: undefined | typeof import('../web/sandbox/context')
let requireCacheHotReloader:
| undefined
| typeof import('../../build/webpack/plugins/nextjs-require-cache-hot-reloader')

if (process.env.NODE_ENV !== 'production') {
sandboxContext = require('../web/sandbox/context')
requireCacheHotReloader = require('../../build/webpack/plugins/nextjs-require-cache-hot-reloader')
}

export function clearModuleContext(target: string, content: string) {
_clearModuleContext(target, content)
sandboxContext?.clearModuleContext(target, content)
}

export function deleteAppClientCache() {
_deleteAppClientCache()
requireCacheHotReloader?.deleteAppClientCache()
}

export function deleteCache(filePath: string) {
_deleteCache(filePath)
requireCacheHotReloader?.deleteCache(filePath)
}

export async function initialize(opts: {
Expand Down

0 comments on commit d06bc5e

Please sign in to comment.