A standalone version of the Next.js Image component for use in non-Next.js projects.
npm install next-image-standalonenext-image-standaloneA standalone version of the
Next.js Image component
for use in non-Next.js projects. This package bundles the actual Next.js Image
component code and its dependencies, allowing you to use it with your own image
optimization backend.
Important Note: This is a purely client-side implementation. Unlike the
standard Next.js Image component, this package does not include any server-side
image optimization logic. All image optimization must be handled by your own
backend service or CDN, which you configure through the loader prop.
``bash`
npm install next-image-standalone
`jsx
import Image from 'next-image-standalone';
// It's required to define a loader function.
const myImageLoader = ({ src, width, quality }) => {
return https://my-cdn.com/${src}?w=${width}&q=${quality};
};
function MyComponent() {
return (
alt="My image"
width={500}
height={300}
loader={myImageLoader}
/>
);
}
`
The component accepts all the **same props as the standard Next.js Image
component**, including src, alt, width, height, and other common image
properties. You can find the complete list of available props in the
Next.js Image component documentation.
One enhancement over the standard Next.js Image component is the **loaderimageProps
prop,** which provides access to the complete set of image properties through
the parameter.
Additionally, you can pass a config prop to customize the image
optimization behavior. This prop accepts the same configuration options that
would normally be set in next.config.js in a Next.js project. However, some
Next.js-specific configuration options are not supported since they require
server-side logic:
- localPatterns: For local image optimization patternsremotePatterns
- : For remote image optimization patternsdomains
- : For allowed image domainsloaderFile`: For custom loader file configuration
-
This package was created with sponsorship from Acquia
through work on Drupal's
Experience Builder.