From 02bc6fcf1d6e6207c46fc6bd4b9037974b3f720b Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Fri, 7 Oct 2022 09:57:08 +0200 Subject: [PATCH] use `next/future/image` if next>=12.3.0 (#870) * use `next/future/image` if next>=12.3.0 * remove from next.config in swr --- .changeset/eighty-icons-fry.md | 5 +++++ examples/swr-site/next.config.js | 3 --- packages/nextra/src/index.js | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/eighty-icons-fry.md diff --git a/.changeset/eighty-icons-fry.md b/.changeset/eighty-icons-fry.md new file mode 100644 index 0000000000..985feb79b2 --- /dev/null +++ b/.changeset/eighty-icons-fry.md @@ -0,0 +1,5 @@ +--- +'nextra': patch +--- + +use `next/future/image` if next>=12.3.0 diff --git a/examples/swr-site/next.config.js b/examples/swr-site/next.config.js index 07b879629f..e08be49a31 100644 --- a/examples/swr-site/next.config.js +++ b/examples/swr-site/next.config.js @@ -65,8 +65,5 @@ module.exports = withNextra({ reactStrictMode: true, experimental: { newNextLinkBehavior: true, - images: { - allowFutureImage: true, - }, }, }); diff --git a/packages/nextra/src/index.js b/packages/nextra/src/index.js index 03994fe624..a972ab6dd5 100644 --- a/packages/nextra/src/index.js +++ b/packages/nextra/src/index.js @@ -1,3 +1,4 @@ +import next from 'next/package.json' import { NextraPlugin, pageMapCache } from './plugin' import { DEFAULT_LOCALE, @@ -7,6 +8,10 @@ import { const DEFAULT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'] +const [major, minor] = next.version.split('.').map(Number) +const nextVersion = major + (0.1 * minor) +const hasFutureImage = nextVersion >= 12.3 + const nextra = (...config) => function withNextra(nextConfig = {}) { const nextraConfig = @@ -41,7 +46,7 @@ const nextra = (...config) => defaultLocale: nextConfig.i18n?.defaultLocale || DEFAULT_LOCALE, pageMapCache, newNextLinkBehavior: nextConfig.experimental?.newNextLinkBehavior, - allowFutureImage: nextConfig.experimental?.images?.allowFutureImage + allowFutureImage: hasFutureImage } config.module.rules.push(