Next.js Project Build and Release Speed Optimization

· 1 min read

Recently worked on a project using Next.js, the entire build and release time consumption was 12min, or longer. Looking at the entire build process, found there were optimization points, marking this here.

Description

CD pipeline uses Tencent Coding.

Pre-optimization Logic

Pipeline directly goes to docker build after pulling, dockerfile has following steps

  1. Builder intermediate process, npm install packages
  2. next build, package frontend resources
  3. run process, install packages, next start project

After Optimization

First about time, average 6min, currently fastest 5min.

  1. CI pipeline loads custom image environment for build, here using nodejs image
  2. Mount /root/workspace/.next/cache and npm cache
  3. Package under custom image, and choose next standalone mode
  4. docker build image doesn’t need multiple steps, only CP all next resources into directory, node server.js start

Note: After optimization, packaged image is 300MB, before optimization was 2GB.

Summary

Minimize build time as much as possible, thereby improving delivery speed.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover