An open API service indexing awesome lists of open source software.

https://github.com/Hugos68/vite-plugin-pagefind

A Vite plugin for easily integrating pagefind into Vite based projects.
https://github.com/Hugos68/vite-plugin-pagefind

pagefind pagefind-js vite vite-plugin vitejs

Last synced: about 2 months ago
JSON representation

A Vite plugin for easily integrating pagefind into Vite based projects.

Awesome Lists containing this project

README

        

# vite-plugin-pagefind

A Vite plugin for easily integrating [Pagefind](https://pagefind.app/) into [Vite](https://vite.dev/) based projects.

## Features

- Pagefind works during development.
- Pagefind can be safely imported.

## Installation

Install from npm using your preferred package manager:

```bash
pnpm add -D pagefind vite-plugin-pagefind
```

## Usage

1. Add the plugin to in `vite.config`:

```ts
import { defineConfig } from "vite";
import { pagefind } from "vite-plugin-pagefind";

export default defineConfig({
plugins: [
pagefind({
outputDirectory: "",
assetsDirectory: "",
bundleDirectory: "",
buildScript: "",
developStrategy: "",
}),
],
});
```

2. Add the post build step of running `pagefind` in your `package.json`:

```json
{
"scripts": {
"": "vite build && pagefind --site \"\""
}
}
```

## Config

### outputDirectory

The directory where the build output is located in.

_default_: 'build'

### assetsDirectory

The directory where the static assets are located in.

_default_: 'public'

### bundleDirectory

The directory where the pagefind bundle is located in.

_default_: 'pagefind'

### buildScript

The script that builds the app.

_default_: 'build'

### developStrategy

The indexing strategy used during development:

- "lazy": Build and index the output only if the bundle is not present.
- "eager": Build and index the output regardless of the bundle's presence.

_default_: 'lazy'

## Types

As well as the plugin, this package also exposes [the official Pagefind types](https://github.com/CloudCannon/pagefind/blob/production-docs/pagefind_web_js/types/index.d.ts):

```ts
import type { Pagefind } from "vite-plugin-pagefind/types";

const pagefind: Pagefind = await import("/pagefind/pagefind.js");
```