Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for leveraging outputStandalone config #32255

Merged
merged 4 commits into from Dec 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/advanced-features/output-file-tracing.md
Expand Up @@ -18,7 +18,26 @@ Next.js' production server is also traced for its needed files and output at `.n

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.

## Automatically Copying Traced Files (experimental)

Next.js can automatically create a `standalone` folder which copies only the necessary files for a production deployment including select files in `node_modules`.

To leverage this automatic copying you can enable it in your `next.config.js`:

```js
module.exports = {
experimental: {
outputStandalone: true,
ijjk marked this conversation as resolved.
Show resolved Hide resolved
},
}
```

This will create a folder at `.next/standalone` which can then be deployed on it's own without installing `node_modules`.

To make leveraging this output easier a minimal `server.js` file is also output which can be used instead of `next start`. This minimal serer does not handle serving the `static` directory as this should be handled by a CDN instead.
ijjk marked this conversation as resolved.
Show resolved Hide resolved

## Caveats

- While tracing in monorepo setups, the project directory is used for tracing by default. For `next build packages/web-app`, `packages/web-app` would be the tracing root and any files outside of that folder will not be included. To include files outside of this folder you can set `experimental.outputFileTracingRoot` in your `next.config.js`.
Copy link
Member

@styfle styfle Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share an example of the outputFileTracingRoot value in this case? Would it be something like outputFileTracingRoot: '../'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an example/normalizing to ensure relative paths are handled but warning that it should be absolute.

- There are some cases that Next.js might fail to include required files, or might incorrectly include unused files. In those cases, you can export page configs props `unstable_includeFiles` and `unstable_excludeFiles` respectively. Each prop accepts an array of [globs](<https://en.wikipedia.org/wiki/Glob_(programming)>) relative to the project's root to either include or exclude in the trace.
- 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](https://vercel.com), to create a minimal deployment. In a future release, a new command is planned to utilize these `.nft.json` files.