Skip to content

Commit 25edbe9

Browse files
committed
Merge branch 'main' into mk/canary-demo
2 parents 30cd451 + 0bcde8d commit 25edbe9

File tree

17 files changed

+140
-87
lines changed

17 files changed

+140
-87
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packages/runtime": "4.23.4",
2+
"packages/runtime": "4.24.0",
33
"packages/next": "1.3.1"
44
}

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ by targeting the `/_next/image/*` route:
4242
X-Test = 'foobar'
4343
```
4444

45+
## Disabling included image loader
46+
47+
If you wish to disable the use of the image loader which is bundled into the runtime by default, set the `DISABLE_IPX` environment variable to `true`.
48+
49+
This should only be done if the site is not using `next/image` or is using a different loader (such as Cloudinary or Imgix).
50+
51+
See the [Next.js documentation](https://nextjs.org/docs/api-reference/next/image#built-in-loaders) for image loader options.
52+
4553
## Next.js Middleware on Netlify
4654

4755
Next.js Middleware works out of the box on Netlify. By default, middleware runs using Netlify Edge Functions. For legacy

demos/default/netlify.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ NODE_VERSION = "16.15.1"
1818
Strict-Transport-Security = "max-age=31536000"
1919
X-Test = 'foobar'
2020

21-
[dev]
22-
framework = "#static"
23-
2421
[[plugins]]
2522
package = "../plugin-wrapper/"
2623

demos/default/next.config.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,18 @@ module.exports = {
7171
},
7272
// https://nextjs.org/docs/basic-features/image-optimization#domains
7373
images: {
74-
domains: ['raw.githubusercontent.com'],
74+
domains: ['raw.githubusercontent.com', 'upload.wikimedia.org'],
75+
remotePatterns: [
76+
{
77+
hostname: '*.imgur.com',
78+
}
79+
]
7580
},
7681
// https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options
7782
sassOptions: {
7883
includePaths: [path.join(__dirname, 'styles-sass-test')],
7984
},
8085
experimental: {
8186
optimizeCss: false,
82-
images: {
83-
remotePatterns: [
84-
{
85-
hostname: '*.imgur.com',
86-
},
87-
],
88-
},
89-
},
87+
}
9088
}

demos/default/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
"npm-run-all": "^4.1.5",
3636
"typescript": "^4.6.3"
3737
}
38-
}
38+
}

demos/default/pages/image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Images = () => (
1515
<p>
1616
<Image src={logo} alt="netlify logomark" />
1717
<Image
18-
src="https://raw.githubusercontent.com/netlify/next-runtime/main/next-on-netlify.png"
18+
src="https://raw.githubusercontent.com/netlify/next-runtime/main/demos/default/public/next-on-netlify.png"
1919
alt="Picture of the author"
2020
width={500}
2121
height={500}

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@babel/preset-env": "^7.15.8",
4949
"@babel/preset-typescript": "^7.16.0",
5050
"@delucis/if-env": "^1.1.2",
51-
"@netlify/build": "^27.20.0",
51+
"@netlify/build": "^27.20.1",
5252
"@netlify/eslint-config-node": "^7.0.0",
5353
"@testing-library/cypress": "^8.0.1",
5454
"@types/fs-extra": "^9.0.13",

packages/runtime/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [4.24.0](https://github.com/netlify/next-runtime/compare/plugin-nextjs-v4.23.4...plugin-nextjs-v4.24.0) (2022-10-03)
4+
5+
6+
### Features
7+
8+
* Add ability to disable ipx ([#1653](https://github.com/netlify/next-runtime/issues/1653)) ([ee7ceda](https://github.com/netlify/next-runtime/commit/ee7ceda4ba7b9822188865cac02074b034b761af))
9+
310
## [4.23.4](https://github.com/netlify/next-runtime/compare/plugin-nextjs-v4.23.3...plugin-nextjs-v4.23.4) (2022-10-03)
411

512

packages/runtime/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netlify/plugin-nextjs",
3-
"version": "4.23.4",
3+
"version": "4.24.0",
44
"description": "Run Next.js seamlessly on Netlify",
55
"main": "lib/index.js",
66
"files": [
@@ -33,7 +33,7 @@
3333
},
3434
"devDependencies": {
3535
"@delucis/if-env": "^1.1.2",
36-
"@netlify/build": "^27.20.0",
36+
"@netlify/build": "^27.20.1",
3737
"@types/fs-extra": "^9.0.13",
3838
"@types/jest": "^27.4.1",
3939
"@types/merge-stream": "^1.1.2",

packages/runtime/src/helpers/config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NetlifyConfig } from '@netlify/build'
2+
import destr from 'destr'
23
import { readJSON, writeJSON } from 'fs-extra'
34
import type { Header } from 'next/dist/lib/load-custom-routes'
45
import type { NextConfigComplete } from 'next/dist/server/config-shared'
@@ -85,10 +86,13 @@ export const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore
8586
const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`))
8687

8788
/* eslint-disable no-underscore-dangle */
88-
netlifyConfig.functions._ipx ||= {}
89-
netlifyConfig.functions._ipx.node_bundler = 'nft'
90-
89+
if (!destr(process.env.DISABLE_IPX)) {
90+
netlifyConfig.functions._ipx ||= {}
91+
netlifyConfig.functions._ipx.node_bundler = 'nft'
92+
}
9193
/* eslint-enable no-underscore-dangle */
94+
95+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
9296
;[HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME].forEach((functionName) => {
9397
netlifyConfig.functions[functionName] ||= { included_files: [], external_node_modules: [] }
9498
netlifyConfig.functions[functionName].node_bundler = 'nft'

packages/runtime/src/helpers/edge.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ export const writeEdgeFunctions = async ({
238238
await copy(getEdgeTemplatePath('../edge-shared'), join(edgeFunctionRoot, 'edge-shared'))
239239
await writeJSON(join(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig)
240240

241-
if (!destr(process.env.NEXT_DISABLE_EDGE_IMAGES) && !destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
241+
if (
242+
!destr(process.env.NEXT_DISABLE_EDGE_IMAGES) &&
243+
!destr(process.env.NEXT_DISABLE_NETLIFY_EDGE) &&
244+
!destr(process.env.DISABLE_IPX)
245+
) {
242246
console.log(
243247
'Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.',
244248
)

packages/runtime/src/helpers/functions.ts

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
22
import bridgeFile from '@vercel/node-bridge'
3+
import destr from 'destr'
34
import { copyFile, ensureDir, writeFile, writeJSON } from 'fs-extra'
45
import type { ImageConfigComplete, RemotePattern } from 'next/dist/shared/lib/image-config'
56
import { join, relative, resolve } from 'pathe'
@@ -55,7 +56,7 @@ export const generatePagesResolver = async ({
5556

5657
// Move our next/image function into the correct functions directory
5758
export const setupImageFunction = async ({
58-
constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC },
59+
constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC, IS_LOCAL },
5960
imageconfig = {},
6061
netlifyConfig,
6162
basePath,
@@ -69,35 +70,50 @@ export const setupImageFunction = async ({
6970
remotePatterns: RemotePattern[]
7071
responseHeaders?: Record<string, string>
7172
}): Promise<void> => {
72-
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
73-
const functionName = `${IMAGE_FUNCTION_NAME}.js`
74-
const functionDirectory = join(functionsPath, IMAGE_FUNCTION_NAME)
73+
const imagePath = imageconfig.path || '/_next/image'
7574

76-
await ensureDir(functionDirectory)
77-
await writeJSON(join(functionDirectory, 'imageconfig.json'), {
78-
...imageconfig,
79-
basePath: [basePath, IMAGE_FUNCTION_NAME].join('/'),
80-
remotePatterns,
81-
responseHeaders,
82-
})
83-
await copyFile(join(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), join(functionDirectory, functionName))
75+
if (destr(process.env.DISABLE_IPX)) {
76+
// If no image loader is specified, need to redirect to a 404 page since there's no
77+
// backing loader to serve local site images once deployed to Netlify
78+
if (!IS_LOCAL && imageconfig.loader === 'default') {
79+
netlifyConfig.redirects.push({
80+
from: `${imagePath}*`,
81+
query: { url: ':url', w: ':width', q: ':quality' },
82+
to: '/404.html',
83+
status: 404,
84+
force: true,
85+
})
86+
}
87+
} else {
88+
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
89+
const functionName = `${IMAGE_FUNCTION_NAME}.js`
90+
const functionDirectory = join(functionsPath, IMAGE_FUNCTION_NAME)
8491

85-
const imagePath = imageconfig.path || '/_next/image'
92+
await ensureDir(functionDirectory)
93+
await writeJSON(join(functionDirectory, 'imageconfig.json'), {
94+
...imageconfig,
95+
basePath: [basePath, IMAGE_FUNCTION_NAME].join('/'),
96+
remotePatterns,
97+
responseHeaders,
98+
})
8699

87-
// If we have edge functions then the request will have already been rewritten
88-
// so this won't match. This is matched if edge is disabled or unavailable.
89-
netlifyConfig.redirects.push({
90-
from: `${imagePath}*`,
91-
query: { url: ':url', w: ':width', q: ':quality' },
92-
to: `${basePath}/${IMAGE_FUNCTION_NAME}/w_:width,q_:quality/:url`,
93-
status: 301,
94-
})
100+
await copyFile(join(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), join(functionDirectory, functionName))
95101

96-
netlifyConfig.redirects.push({
97-
from: `${basePath}/${IMAGE_FUNCTION_NAME}/*`,
98-
to: `/.netlify/builders/${IMAGE_FUNCTION_NAME}`,
99-
status: 200,
100-
})
102+
// If we have edge functions then the request will have already been rewritten
103+
// so this won't match. This is matched if edge is disabled or unavailable.
104+
netlifyConfig.redirects.push({
105+
from: `${imagePath}*`,
106+
query: { url: ':url', w: ':width', q: ':quality' },
107+
to: `${basePath}/${IMAGE_FUNCTION_NAME}/w_:width,q_:quality/:url`,
108+
status: 301,
109+
})
110+
111+
netlifyConfig.redirects.push({
112+
from: `${basePath}/${IMAGE_FUNCTION_NAME}/*`,
113+
to: `/.netlify/builders/${IMAGE_FUNCTION_NAME}`,
114+
status: 200,
115+
})
116+
}
101117

102118
if (basePath) {
103119
// next/image generates image static URLs that still point at the site root

packages/runtime/src/helpers/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,5 @@ export const getRemotePatterns = (experimental: ExperimentalConfigWithLegacy, im
228228
}
229229
return []
230230
}
231+
231232
/* eslint-enable max-lines */

0 commit comments

Comments
 (0)