Output File Tracing
This feature helps reduce the size of deployments drastically. Previously, when deploying with Docker you would need to have all files from your package’s installed to run next start
. Starting with Next.js 12, you can leverage Output File Tracing in the .next/
directory to only include the necessary files.
Furthermore, this removes the need for the deprecated serverless
target which can cause various issues and also creates unnecessary duplication.
Next.js’ production server is also traced for its needed files and output at .next/next-server.js.nft.json
which can be leveraged in production.
To leverage the .nft.json
files emitted to the .next
output directory, you can read the list of files in each trace which are relative to the .nft.json
file and then copy them to your deployment location.
To leverage this automatic copying you can enable it in your :
This will create a folder at .next/standalone
which can then be deployed on it’s own without installing node_modules
.
Note: next.config.js
is read during next build
and serialized into the server.js
output file. If the legacy serverRuntimeConfig or publicRuntimeConfig options are being used, the values will be specific to values at build time.
// packages/web-app/next.config.js
module.exports = {
experimental: {
outputFileTracingRoot: path.join(__dirname, '../../'),
},
}
- Currently, Next.js does not do anything with the emitted
.nft.json
files. The files must be read by your deployment platform, for example Vercel, to create a minimal deployment. In a future release, a new command is planned to utilize these.nft.json
files.