Configured Next.js build settings to support static export for Contentful App hosting
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
1. Run npm run build to confirm the build generates static files in the out directory.
2. Run npm run upload to deploy the app to Contentful.
3. Open the app in Contentful to ensure it loads correctly with all assets displaying as expected.
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.
Deploy request for ecommerce-app-base-components pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | 033126952ec82459e45f429c411bacf7ccdec972 |