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

Create static JSON config file for standalone server output #76732

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

iiroj
Copy link

@iiroj iiroj commented Mar 2, 2025

What?

Instead of inlining the build-time JSON config to the server.js file generated to the standalone output of Next.js build (with config option output: 'standalone', this PR changes the the build process to emit a separate JSON file which is required into the server.js file.

Why?

It's cleaner to separate the config into its own file, since it's static JSON anyway. This change also makes it easier for one to create their own server.js file.

How?

Instead of inlining the JSON.stringify(nextConfig) content into the generated server.js file, write a separate file next.config.json next to it, and use the already-created require to load it. This should work with both CommonJS and ESM since the createRequire is already configured. The require automatically parses JSON.

I did not add new tests because this should not change existing behavior, and there's plenty of existing tests for the standalone build output; and if this was broken, hopefully some of them would fail.

@ijjk ijjk added the type: next label Mar 2, 2025
@ijjk
Copy link
Member

ijjk commented Mar 2, 2025

Allow CI Workflow Run

  • approve CI run for commit: a59057e

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@iiroj
Copy link
Author

iiroj commented Mar 2, 2025

The test production/standalone-mode/required-server-files/required-server-files.test.ts contains three assertions for the configuration content, which need to be updated to read the JSON instead:

    ✕ `compress` should be `false` in nextEnv (200 ms)
    ✕ `cacheHandler` should have correct path (194 ms)
    ✕ `cacheMaxMemorySize` should be disabled by setting to 0 (191 ms)

EDIT: ✅ updated the tests

@iiroj iiroj force-pushed the standalone-json-config branch from 29e5f87 to cd4690a Compare March 2, 2025 20:18
@ijjk ijjk added the tests label Mar 2, 2025
@iiroj iiroj force-pushed the standalone-json-config branch from cd4690a to a59057e Compare March 3, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants