Configuration
Image loaderFile
Set images.loader to custom and loaderFile to a project-relative module. Its default export maps source, width and quality to an image URL. The illustrative loader accepts only catalog asset keys and constructs a URL on a reserved example domain; a real service must implement its own allowlist and authorization. Source: https://nextjs.org/docs/app/api-reference/components/image. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.
Formal Syntax & Structure
nextjs syntaxnextjs
images: { loader: "custom", loaderFile: "./image-loader.js" }Working Example
Example Snippetnextjs
'use client';export default function loader({src,width,quality}:{src:string;width:number;quality?:number}) { if (!/^\/covers\/[a-z0-9-]+\.png$/.test(src)) throw new Error('Unsupported asset'); const url=new URL('https://covers.example.com/render'); url.searchParams.set('asset',src); url.searchParams.set('w',String(width)); url.searchParams.set('q',String(quality ?? 75)); return url.toString();}