Skip to content

Commit

Permalink
Feature: 1.0.0 (#62)
Browse files Browse the repository at this point in the history
* stuff

* v1

* fixes

* fixes
  • Loading branch information
Hugos68 authored Jan 21, 2025
1 parent 7f1e203 commit 4bcd5f9
Show file tree
Hide file tree
Showing 18 changed files with 1,168 additions and 1,225 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-cheetahs-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-pagefind": minor
---

Chore: Removed ability to use `pagefind.json`, config is now fully inline.
5 changes: 5 additions & 0 deletions .changeset/four-suits-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-pagefind": major
---

Feature: 1.0.0 🎉
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Editors
.vscode
.idea

# Artifacts
.vscode
dist
node_modules
dist
21 changes: 0 additions & 21 deletions LICENSE.txt

This file was deleted.

97 changes: 27 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# vite-plugin-pagefind

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

## Features

- Ensures pagefind is present during development.
- Ensures pagefind can be safely used through dynamic imports in conjunction with Vite.

## Why?

Read about the reasoning for this plugin here: [https://hugokorte.pages.dev/articles/pagefind-with-vite](https://portfolio-2-70z.pages.dev/blog/pagefind-with-vite/)
- Pagefind works during development.
- Pagefind can be safely imported.

## Installation

Expand All @@ -21,115 +17,76 @@ pnpm add -D pagefind vite-plugin-pagefind

## Usage

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

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

export default defineConfig({
plugins: [pagefind()],
});
```

You can pass the options to the plugin directly in your Vite configuration:

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

export default defineConfig({
plugins: [
pagefind({
site: "<BUILD_DIR>",
assets_dir: "<ASSETS_DIR>",
pagefind_dir: "<PAGEFIND_DIR>",
build_command: "<BUILD_COMMAND>",
dev_strategy: "<DEV_STRATEGY>",
outputDirectory: "<OUTPUT_DIRECTORY>",
assetsDirectory: "<ASSETS_DIRECTORY>",
bundleDirectory: "<BUNDLE_DIRECTORY>",
buildScript: "<BUILD_SCRIPT>",
developStrategy: "<DEVELOP_STRATEGY>",
}),
],
});
```

Note: If you decide to use an inline config, you would still need to add the `--site` flag to your `pagefind` command.

Note: If your framework does not have a `vite.config` consider consulting the framework documentation to see how to add a Vite plugin.

2. Add the post build command to your `package.json`:
2. Add the post build step to your `<OUTPUT_DIRECTORY>` in your `package.json`:

```json
{
"scripts": {
"build": "vite build && pagefind"
}
}
```

3. If you didn't pass the configuration options to the plugin, you can use the `pagefind.json` file to configure the plugin, as shown:

```json
{
"site": "<BUILD_DIR>",
"vite_plugin_pagefind": {
"assets_dir": "<ASSETS_DIR>",
"pagefind_dir": "<PAGEFIND_DIR>",
"build_command": "<BUILD_COMMAND>",
"dev_strategy": "<DEV_STRATEGY>"
"build": "vite build && pagefind --site \"<OUTPUT_DIRECTORY>\""
}
}
```

If for some reason you decide to define your configuration in both the file and the Vite configuration, the file will take precedence over the inline Vite configuration.

Note: `vite-plugin-pagefind` currently only supports `.json` files, more are planned be supported in the future.

## Config

### site
### outputDirectory

The directory where the build output is located in.

The directory where your build output lives, this is required for both pagefind and this plugin.
_default_: 'build'

### assets_dir
### assetsDirectory

The directory where the static assets are located relative to the project's root as specified in the Vite config.
The directory where the static assets are located in.

_default_: 'public'

### pagefind_dir
### bundleDirectory

The directory part of the URL you use to import the pagefind script on your site. For example, if you use `/pagefind/pagefind.js`, the `pagefind_dir` is `pagefind`. If you use `/search/static/pagefind/pagefind.js`, the `pagefind_dir` is `search/static/pagefind`.
The directory where the pagefind bundle is located in.

_default_: 'pagefind'

### build_command
### buildScript

The command to build and index the project.
The script that builds the app.

_default_: 'npm run build'
_default_: 'build'

### dev_strategy
### developStrategy

The indexing strategy used during development:

- "eager": Build and index the app every time the development server starts
- "lazy": Build and index the app only if the pagefind bundle isn't present already
- "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

Apart from the plugin, this package also exposes [the types from pagefind](https://github.com/CloudCannon/pagefind/blob/production-docs/pagefind_web_js/types/index.d.ts) as well as extending them by providing an additional `Pagefind` type:
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");
```

## Pagefind

For further questions regarding Pagefind itself you can refer to [the official docs](https://pagefind.app/).

## License

This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
13 changes: 2 additions & 11 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["dist/**"]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
"ignore": ["dist", "node_modules"]
}
}
14 changes: 14 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineBuildConfig } from "unbuild";

const config = defineBuildConfig({
entries: ["src/index.ts", "src/types.ts"],
outDir: "dist",
clean: true,
declaration: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
},
});

export default config;
50 changes: 19 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
{
"name": "vite-plugin-pagefind",
"description": "A Vite plugin for easily integrating pagefind into Vite based projects.",
"version": "0.3.0",
"license": "MIT",
"author": {
"name": "Hugo Korte",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "https://github.com/Hugos68/vite-plugin-pagefind"
},
"homepage": "https://github.com/Hugos68/vite-plugin-pagefind#vite-plugin-pagefind",
"keywords": [
"vite",
"vite-plugin",
"pagefind"
],
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"main": "./dist/plugins/pagefind.js",
"files": ["dist"],
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/plugins/pagefind.d.ts",
"import": "./dist/plugins/pagefind.js"
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./types": {
"types": "./dist/types/pagefind.d.ts",
"import": "./dist/types/pagefind.js"
"require": "./dist/types.cjs",
"import": "./dist/types.mjs",
"types": "./dist/types.d.ts"
}
},
"scripts": {
"build": "tsc",
"format": "biome format "
"build": "unbuild",
"build:watch": "unbuild --watch",
"check": "biome check",
"check:fix": "biome check --write",
"prepack": "unbuild"
},
"dependencies": {
"colorette": "^2.0.20",
"valibot": "0.31.0-rc.4"
"package-manager-detector": "^0.2.8"
},
"peerDependencies": {
"vite": "^6.0.0"
},
"devDependencies": {
"@biomejs/biome": "1.7.3",
"@changesets/cli": "^2.27.10",
"@types/node": "^20.17.9",
"typescript": "^5.7.2",
"unbuild": "^2.0.0"
"@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.27.11",
"@types/node": "^22.10.7",
"typescript": "^5.7.3",
"unbuild": "^3.3.1"
},
"type": "module"
}
Loading

0 comments on commit 4bcd5f9

Please sign in to comment.