@spacefast/image
v0.8.0
Published
Helpers for generating WordPress.com Site Accelerator image URLs.
Readme
@spacefast/image
Small helpers for generating WordPress.com Site Accelerator image URLs.
Use this package when a Spacefast space or integration needs predictable image resizing and optimization URLs without hand-building query strings.
Install
npm install @spacefast/imageUsage
import { siteAcceleratorUrl } from "@spacefast/image";
const src = siteAcceleratorUrl("https://example.com/photo.jpg", {
w: 1200,
quality: 80,
strip: "all",
});Absolute http and https URLs are rewritten through the Site Accelerator
host. Relative paths are returned unchanged, so the helper is safe to call with
mixed local and remote image sources.
Next.js
Spread the image config and point loaderFile at a one-line file in your
project. Next resolves that path against the project root and bundles it for
the browser, which is why it is a local file and not a path into
node_modules.
import type { NextConfig } from "next";
import { spacefastNextImageConfig } from "@spacefast/image/next";
const config: NextConfig = {
images: {
...spacefastNextImageConfig,
loaderFile: "./spacefast-image-loader.ts",
},
};
export default config;"use client";
export { default } from "@spacefast/image/next-loader";The client directive lets Server Components render next/image with the
loader. Then use next/image as usual:
import Image from "next/image";
export default function Page() {
return (
<Image
src="https://example.com/photo.jpg"
alt="Example photo"
width={800}
height={600}
quality={85}
/>
);
}Verified on Next 15.5 and 16.x. bun run test:next checks one pinned Next 16
release by default; pass versions to check others. It packs this package,
installs it into a fresh Next project built from the code blocks above, runs
next build, and checks the rendered <img>.
