Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1.39 KB

README.md

File metadata and controls

49 lines (37 loc) · 1.39 KB

GitHub package.json version npm bundle size GitHub Workflow Status NPM

lup-images

Node module for optimizing images in web applications.

Example Server

const { ImagesRequestHandler } = require('lup-images');
const express = require('express');

const app = express();

app.use('/images/*', ImagesRequestHandler());

app.listen();

Example JSX

<OptimizedImage src="https://picsum.photos/200/300" width={200} height={300} />

For NextJS

To work with NextJS you need to add the following to your next.config.js:

experimental: {
    serverComponentsExternalPackages: ["sharp"],
}

Prerender Images before Deployment

Images can also be prerendered before deployment e.g. inside of a CI/CD pipeline. Create a file that contains the following code:

import { PrerenderImages } from 'lup-images';

// this wrapper is needed if you are in the main file of a node project
(async () => {

    // prerender images (provide same options as in the request handler)
    await PrerenderImages({ ... });

})();

In the CI/CD pipeline or wherever you want to prerender the images, run the file using node.