Configured Next.js build settings to support static export for Contentful App hosting #9998
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Contentful apps require static file deployment in order to be hosted. This change ensures that the Next.js app is exported as static HTML, CSS, and JS files rather than running as a server, aligning it with Contentful’s hosting requirements.
Approach
We configured the Next.js app for static export by:
• Adding output: "export" to generate static HTML files.
• Setting distDir: 'out' to match Contentful’s expected build output directory.
• Configuring images.unoptimized: true for static export compatibility.
• Adding assetPrefix: './' for proper asset loading in static contexts.
• Adding an upload script to package.json for easy deployment to Contentful.
We considered alternatives such as deploying with server-side rendering, but Contentful hosting requires static assets.
Testing steps
Breaking Changes
This configuration is necessary for deployment but does not break existing local development workflows.
Dependencies and/or References
Next.js Static HTML Export documentation
Deployment
No special deployment considerations. After merging, developers can run the upload script to deploy the static app to Contentful.