Install with Next.js
Wrap the Next.js config with withDiorama and start the app from a client component.
Next.js builds with webpack or Turbopack, not Vite. withDiorama writes the effect registry and its types to src/diorama.gen.ts and points both bundlers at it. Effects go in src/effects/.
Install the packages
npm install @dioramajs/diorama threepnpm add @dioramajs/diorama threeyarn add @dioramajs/diorama threebun add @dioramajs/diorama threeWrap the config
import { function withDiorama<T extends object = NextConfigLike>( config: T & NextConfigLike, options?: WithDioramaOptions): T
Wraps a Next config so the effects folder becomes @dioramajs/diorama/generated.
withDiorama } from '@dioramajs/diorama/next'
export default withDiorama<{}>( config: NextConfigLike, options?: WithDioramaOptions): {}
Wraps a Next config so the effects folder becomes @dioramajs/diorama/generated.
withDiorama({})Start the app from a client component
'use client'import { start } from '@dioramajs/diorama'import { useEffect } from 'react'
export function Diorama() { useEffect(() => void start(), []) return null}Render <Diorama /> once in the root layout.
import type { ReactNode } from 'react'import { Diorama } from './diorama'
export default function RootLayout({ children,}: { children: ReactNode}) { return ( <html lang="en"> <body> {children} <Diorama /> </body> </html> )}Put an effect on an image
export default function Page() { return ( <img src="/cover.jpg" width={800} height={450} data-dio="ripple" /> )}Commit src/diorama.gen.ts. In development new and removed effect files are picked up on their own, and Fast Refresh replaces an edited effect.