Skip to content

Commit a64130e

Browse files
authored
doc: add build lifecycle hooks documentation (#78842)
Added documentation for the new Build Lifecycle Hooks feature in the Next.js Compiler, specifically the `runAfterProductionCompile` hook. #77345
1 parent 6dbaf95 commit a64130e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/03-architecture/nextjs-compiler.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,29 @@ module.exports = {
278278
}
279279
```
280280

281+
### Build Lifecycle Hooks
282+
283+
The Next.js Compiler supports lifecycle hooks that allow you to run custom code at specific points during the build process. Currently, the following hook is supported:
284+
285+
#### runAfterProductionCompile
286+
287+
A hook function that executes after production build compilation finishes, but before running post-compilation tasks such as type checking and static page generation. This hook provides access to project metadata including the project directory and build output directory, making it useful for third-party tools to collect build outputs like sourcemaps.
288+
289+
```js filename="next.config.js"
290+
module.exports = {
291+
compiler: {
292+
runAfterProductionCompile: async ({ distDir, projectDir }) => {
293+
// Your custom code here
294+
},
295+
},
296+
}
297+
```
298+
299+
The hook receives an object with the following properties:
300+
301+
- `distDir`: The build output directory (defaults to `.next`)
302+
- `projectDir`: The root directory of the project
303+
281304
## Experimental Features
282305

283306
### SWC Trace profiling

0 commit comments

Comments
 (0)