1.4.6 • Published 5 months ago

@netlify/ipx v1.4.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Netlify Optimized Images

On Demand image optimization for Netlify using ipx.

😺 Online demo: https://netlify-ipx.netlify.app

Usage

Add @netlify/ipx as devDependency:

# npm
npm i -D @netlify/ipx

# yarn
yarn add --dev @netlify/ipx

Create netlify/functions/ipx.ts:

import { createIPXHandler } from "@netlify/ipx";

export const handler = createIPXHandler({
  domains: ["images.unsplash.com"],
});

Now you can use IPX to optimize both local and remote assets ✨

Resize /test.jpg (in dist):

<img src="/.netlify/functions/ipx/w_200/static/test.jpg" />

Resize and change format for a remote url:

<img
  src="/.netlify/functions/ipx/f_webp,w_450/https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba"
/>

Remote Patterns

Instead of setting an allowlist on domains, you may wish to use the option remotePatterns. This method allows wildcards in hostname and pathname segments.

remotePatterns is an array that contains RemotePattern objects:

remotePatterns: [
  {
    protocol: 'https' // or 'http' - not required
    hostname: 'example.com' // required
    port: '3000' // not required
    pathname: '/blog/**' // not required
  }
]

To use remote patterns, create netlify/functions/ipx.ts:

import { createIPXHandler } from "@netlify/ipx";

export const handler = createIPXHandler({
  remotePatterns: [
    {
      protocol: "https",
      hostname: "images.unsplash.com",
    },
  ],
});

hostname and pathname may contain wildcards:

remotePatterns: [
  {
    hostname: '*.example.com' // * = match a single path segment or subdomain
    pathname: '/blog/**' // ** = match any number of path segments or subdomains
  }
]

Local development

  • Clone repository
  • Install dependencies with yarn install
  • Build the project with yarn build
  • Run netlify development server with yarn dev.
  • Open http://localhost:8888

License

MIT

1.4.6

5 months ago

1.4.5

7 months ago

1.4.4

8 months ago

1.4.3

8 months ago

1.4.2

9 months ago

1.4.6-0

6 months ago

1.4.2-waf-header.0

9 months ago

1.4.1

10 months ago

1.4.0

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.4

2 years ago

1.2.2

2 years ago

1.1.3

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago