Skip to content

Commit

Permalink
use next/future/image if next>=12.3.0 (#870)
Browse files Browse the repository at this point in the history
* use `next/future/image` if next>=12.3.0

* remove from next.config in swr
  • Loading branch information
dimaMachina committed Oct 7, 2022
1 parent b7f7cf6 commit 02bc6fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-icons-fry.md
@@ -0,0 +1,5 @@
---
'nextra': patch
---

use `next/future/image` if next>=12.3.0
3 changes: 0 additions & 3 deletions examples/swr-site/next.config.js
Expand Up @@ -65,8 +65,5 @@ module.exports = withNextra({
reactStrictMode: true,
experimental: {
newNextLinkBehavior: true,
images: {
allowFutureImage: true,
},
},
});
7 changes: 6 additions & 1 deletion packages/nextra/src/index.js
@@ -1,3 +1,4 @@
import next from 'next/package.json'
import { NextraPlugin, pageMapCache } from './plugin'
import {
DEFAULT_LOCALE,
Expand All @@ -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 =
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 02bc6fc

Please sign in to comment.