Installation

Prerequisites

  • Node.js 18+
  • Angular 18+ with NgOptimizedImage
  • SSR mode: Angular SSR with an Express server entry (server.ts)
  • AOT mode: A production build pipeline (no runtime server required for images)

Quick start (schematic)

The fastest path is ng add, which installs dependencies and wires the correct provider for your chosen mode:

bash
ng add ng-image-optimizer --mode=SSR
bash
ng add ng-image-optimizer --mode=AOT

Manual install

bash
npm install ng-image-optimizer sharp

sharp is required for SSR middleware and for the AOT CLI. It is listed as an optional dependency but should be installed explicitly in your app.

After install

Complete mode-specific setup — only one path applies to your app:

  • SSR:provideImageOptimizerLoader + imageOptimizerHandler — see SSR Setup
  • AOT:provideAotImageLoader + ng-image-optimizer-aot postbuild — see AOT Setup