# Install with Vite

Add Diorama to a Vite site with the plugin that finds your effects and writes their types.

The Vite plugin turns every file in `src/effects/` into an effect that loads on demand and writes the types of those effects to `src/diorama.gen.d.ts`. It works with any framework that builds with Vite.

## Install the packages

### npm

```sh
npm install @dioramajs/diorama three
```

### pnpm

```sh
pnpm add @dioramajs/diorama three
```

### yarn

```sh
yarn add @dioramajs/diorama three
```

### bun

```sh
bun add @dioramajs/diorama three
```

## Add the plugin

Add `diorama()` to the plugins in `vite.config.ts`.

```ts title="vite.config.ts"
import { diorama } from '@dioramajs/diorama/vite'

export default { plugins: [diorama()] }
```

## Start the app

Call `start()` once in the module every page loads.

```ts title="src/main.ts"
import { start } from '@dioramajs/diorama'

export const app = start()
```

## Put an effect on an image

Add `data-dio` with an effect name to an element. The `ripple` effect comes with `start()`.

```html title="index.html"
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Diorama</title>
    <script type="module" src="/src/main.ts"></script>
  </head>
  <body>
    <img
      src="/cover.jpg"
      width="800"
      height="450"
      data-dio="ripple"
    />
  </body>
</html>
```

Run the dev server and move the pointer over the image. Rings spread from the pointer, and the image keeps its place in the layout while you scroll.

Note: The plugin writes `src/diorama.gen.d.ts` whenever the effects folder changes. Commit it, so `app.attach()` checks effect names and params in CI as well.

## Plugin options

| Name | Type | Description |
| --- | --- | --- |
| `dir?` | `string` | The effects folder, relative to the Vite root. Default 'src/effects'. |
| `types?` | `string \| false` | The types file, relative to the root, or `false` for none. Default 'src/diorama.gen.d.ts'. |
