-
Notifications
You must be signed in to change notification settings - Fork 83
Add image optimization with Cloudflare Images #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
ab5bec8
4e4a7f9
7868b9d
2abe65a
0833f86
4260cd0
3555c3e
fb34836
046a327
0d04a5e
476fe2f
c272ea1
afed612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,5 +44,8 @@ | |
| "database_id": "db_id", | ||
| "database_name": "db_name" | ||
| } | ||
| ] | ||
| ], | ||
| "images": { | ||
| "binding": "IMAGES" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,29 +19,53 @@ export async function compileImages(options: BuildOptions) { | |
| : {}; | ||
|
|
||
| const __IMAGES_REMOTE_PATTERNS__ = JSON.stringify(imagesManifest?.images?.remotePatterns ?? []); | ||
| const __IMAGES_LOCAL_PATTERNS_DEFINED__ = JSON.stringify( | ||
|
||
| Array.isArray(imagesManifest?.images?.localPatterns) | ||
| ); | ||
| const __IMAGES_LOCAL_PATTERNS__ = JSON.stringify(imagesManifest?.images?.localPatterns ?? []); | ||
| const __IMAGES_DEVICE_SIZES__ = JSON.stringify(imagesManifest?.images?.deviceSizes ?? defaultDeviceSizes); | ||
| const __IMAGES_IMAGE_SIZES__ = JSON.stringify(imagesManifest?.images?.imageSizes ?? defaultImageSizes); | ||
| const __IMAGES_QUALITIES__ = JSON.stringify(imagesManifest?.images?.qualities ?? defaultQualities); | ||
| const __IMAGES_FORMATS__ = JSON.stringify(imagesManifest?.images?.formats ?? defaultFormats); | ||
| const __IMAGES_MINIMUM_CACHE_TTL__ = JSON.stringify( | ||
| imagesManifest?.images?.minimumCacheTTL ?? defaultMinimumCacheTTL | ||
| ); | ||
| const __IMAGES_ALLOW_SVG__ = JSON.stringify(Boolean(imagesManifest?.images?.dangerouslyAllowSVG)); | ||
| const __IMAGES_CONTENT_SECURITY_POLICY__ = JSON.stringify( | ||
| imagesManifest?.images?.contentSecurityPolicy ?? "script-src 'none'; frame-src 'none'; sandbox;" | ||
| ); | ||
| const __IMAGES_CONTENT_DISPOSITION__ = JSON.stringify( | ||
| imagesManifest?.images?.contentDispositionType ?? "attachment" | ||
| ); | ||
| const __IMAGES_MAX_REDIRECTS__ = JSON.stringify(imagesManifest?.images?.maximumRedirects ?? 3); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was changed to 3 from unlimited in Next.js 16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use unlimited then (and maybe add your comment as a code comment on this file/line)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the status here? |
||
|
|
||
| await build({ | ||
| entryPoints: [imagesPath], | ||
| outdir: path.join(options.outputDir, "cloudflare"), | ||
| bundle: false, | ||
| bundle: true, | ||
vicb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| minify: false, | ||
| format: "esm", | ||
| target: "esnext", | ||
| platform: "node", | ||
| define: { | ||
| __IMAGES_REMOTE_PATTERNS__, | ||
| __IMAGES_LOCAL_PATTERNS_DEFINED__, | ||
| __IMAGES_LOCAL_PATTERNS__, | ||
| __IMAGES_DEVICE_SIZES__, | ||
| __IMAGES_IMAGE_SIZES__, | ||
| __IMAGES_QUALITIES__, | ||
| __IMAGES_FORMATS__, | ||
| __IMAGES_MINIMUM_CACHE_TTL__, | ||
| __IMAGES_ALLOW_SVG__, | ||
| __IMAGES_CONTENT_SECURITY_POLICY__, | ||
| __IMAGES_CONTENT_DISPOSITION__, | ||
| __IMAGES_MAX_REDIRECTS__, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const defaultDeviceSizes = [640, 750, 828, 1080, 1200, 1920, 2048, 3840]; | ||
| const defaultImageSizes = [32, 48, 64, 96, 128, 256, 384]; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before Next.js 16,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use Next 16 (and add comments on the lines). nit: maybe move those constants up (i.e. before they are used)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the status here? |
||
| const defaultQualities = [75]; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before Next.js 16, the default behavior was to allow values from 1-100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the status here? |
||
| const defaultFormats = ["image/webp"]; | ||
| const defaultMinimumCacheTTL = 14400; | ||
Uh oh!
There was an error while loading. Please reload this page.