Skip to content

Commit

Permalink
Fixed pagefind running after build
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugos68 committed Jan 27, 2024
1 parent 0d29ad3 commit bd97d3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-papayas-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-pagefind': patch
---

Finally fixed running pagefind after build
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Patch Changes

- 9bdcc49: Fixed pagefind post build not running after the build process
- 9bdcc49: Fixed pagefind post build not running after the build process

## 0.0.6

Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PluginOption } from 'vite';
import type { PluginOption, ResolvedConfig } from 'vite';
import { join } from 'path';
import { existsSync } from 'fs';
import { execSync } from 'child_process';
Expand All @@ -25,7 +25,6 @@ function pagefindDev({
}: PagefindDevConfig): PluginOption {
return {
name: 'pagefind-dev',
enforce: 'pre',
apply: 'serve',
configureServer() {
if (!existsSync(pagefindDir)) {
Expand All @@ -47,11 +46,17 @@ function pagefindDev({
}

function pagefindBuild({ siteDir, cwd }: PagefindBuildConfig): PluginOption {
let config: ResolvedConfig | null = null;
return {
name: 'pagefind-build',
enforce: 'post',
apply: 'build',
configResolved(_config: ResolvedConfig) {
config = _config;
},
closeBundle() {
if (!config?.build.ssr) {
return;
}
log('Running pagefind...');
execSync(`pagefind --site "${siteDir}"`, { cwd });
log('Pagefind complete.');
Expand Down

0 comments on commit bd97d3d

Please sign in to comment.