Script: next dev vs next build vs next start
In Next.js, next dev
is used to run the app in development mode. On the other hand, `next start` is used to run the app in production mode, but requires `next build` to be run first to generate an optimized production build.
Development
When running the Next.js app in development, you'll want to use `next dev`:
next dev
starts the application in development mode with hot-code reloading, error reporting, and more.
Production
When building the Next.js app for production, you'll want to use `next build`:
next build
creates an optimized production build of your application. The output displays information about each route.
- Size – The number of assets downloaded when navigating to the page client-side. The size for each route only includes its dependencies.
- First Load JS – The number of assets downloaded when visiting the page from the server. The amount of JS shared by all is shown as a separate metric.
Followed by either next start
, when you want to start the production server:
next start
starts the application in production mode. The application should be compiled with `next build` first.
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
}