out.
Configure Next.js
Turn on static export innext.config.ts, and write each page as a folder with an index.html. On an older project, the same options go in next.config.js or next.config.mjs:
next.config.ts
trailingSlash, Next.js writes /about as about.html, and a request for /about returns a 404.
images.unoptimized lets next/image build without the image optimisation server, which a static export doesn’t have, and serves every image at full size. To resize them at the edge, see Resize images with Bunny Optimizer. A static export also can’t use other features that need a server, such as API routes. See the Next.js static exports guide for the full list. To run Next.js with a server, deploy it with Magic Containers.
Deploy your site
- Bunny CLI
- Manually
1
Install the Bunny CLI and log in
2
Create a site
From your project root, run:Replace
my-site with a name for your site. The CLI creates a storage zone for your files and a pull zone to serve them, then links this directory to the new site. The site is served at a b-cdn.net address, and the CLI prints the URL.3
Build and deploy
bunny sites deployments publish --previous.4
Deploy on every push (optional)
.github/workflows/bunny-sites.yml that deploys the site on every push to main. Add your API key to the repository as a BUNNYNET_API_KEY secret. The CLI offers to run gh secret set BUNNYNET_API_KEY for you.Resize images with Bunny Optimizer
A custom loader pointsnext/image at Bunny Optimizer, which resizes each image at the edge for every width in the srcset. The example app has the full setup.
1
Turn on Optimizer
bunny sites create leaves query strings and Optimizer off, so open the site’s pull zone under CDN → Pull Zones:- Turn on URL Query String vary, so each
?width=gets its own cache entry. - Enable Bunny Optimizer, then turn on the Dynamic Image API and automatic WebP under Optimizer → Settings. Your build has already minified CSS and JavaScript, so turn Optimizer’s minification off.
2
Add the loader
The loader adds
?width= and ?quality= to each image URL. It needs "use client" because the App Router sends the loader to the browser.lib/bunny-loader.ts
3
Swap unoptimized for the loader
next.config.ts
srcset URLs on each page carry ?width=.src stay, so Dynamic Image API options such as ?aspect_ratio=1:1 combine with the responsive widths. Next.js 16 only accepts quality 75 unless you list other values in images.qualities.
Add a custom domain
With the Bunny CLI, add the domain to your site:CNAME record to create with your DNS provider. Once the record resolves, issue a free certificate with bunny sites domains ssl example.com.
For a manual deploy, add the hostname to your pull zone by following Custom hostnames.