styxlab / next-cms-ghost

Publish flaring fast blogs with Next.js and Ghost CMS
https://next.jamify.org
MIT License
670 stars 203 forks source link

Feature: Support next export #29

Closed styxlab closed 3 years ago

styxlab commented 3 years ago

Currently, when you run next export in this repository, you'll get the following error message:

Error: Image Optimization using Next.js' default loader is not compatible with `next export`.
Possible solutions:
  - Use `next start`, which starts the Image Optimization API.
  - Use Vercel to deploy, which supports Image Optimization.
  - Configure a third-party loader in `next.config.js`.

Option 3 should be used to make next export available here. Some more investigation is needed on how to make this work.

rahulsuresh-git commented 3 years ago

Thanks for opening this @styxlab As I said, I need next export so that I can host it on an S3 bucket. Is there any other way to host it on AWS that you are aware of, which doesn't require a next export?

styxlab commented 3 years ago

If you are serving from a static-only host, then next export is needed, but it is not encouraged as you have to opt out from image optimizations and incremental static regeneration (ISR).

styxlab commented 3 years ago

It is already possible to use next export with the following configuration options:

  1. Disable image optimization and ISR in appConfig.js:
// Images
export const nextFeatureImages: boolean = false
export const nextInlineImages: boolean = false

// Incremental Static Regenerations (ISR)
export const isr: boolean = false
  1. Change default image loader in next.config.js
module.exports = withBundleAnalyzer({
  ...(process.env.NETLIFY === 'true' && { target: 'serverless' }),
  images: {
    loader: 'imgix',
    deviceSizes: [320, 500, 680, 1040, 2080, 2048, 3120],
    domains: ['localhost', 'images.unsplash.com', 'static.gotsby.org', 'static.ghost.org'],
  },
  reactStrictMode: true,
})

The deviceSizes and domains props can be deleted or left in. Note that the 'imgix' loader is not used, it must be a Next.js supported loader different from the default loader.

Here is the standard warning from 'Next.js' when using their export method:

warn  - Statically exporting a Next.js application via `next export` disables API routes.
This command is meant for static-only hosts, and is not necessary to make your application static.
Pages in your application without server-side data dependencies will be automatically statically exported by `next build`, including pages powered by `getStaticProps`.
Learn more: https://err.sh/vercel/next.js/api-routes-static-export

@icy-meteor Could you please verify?

rahulsuresh-git commented 3 years ago

Got past the image optimisation error but fails with the following error : image

styxlab commented 3 years ago

You forgot to disable ISR.

rahulsuresh-git commented 3 years ago

Oops, my bad :) Yes, works now! Confirmed.