Skip to content

Commit f038428

Browse files
committed
docs: updated sveltekit usage
1 parent cbf2062 commit f038428

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img src="https://raw.githubusercontent.com/GauBen/formgator/refs/heads/main/formgator.jpg" alt="Ali, the friendly alligator that guards your forms" width="200" height="200">
33
</div>
44

5-
# formgator
5+
# Formgator
66

77
A validation library for JavaScript `FormData` and `URLSearchParams` objects.
88

@@ -187,9 +187,16 @@ If some fields were accepted nonetheless, the `error` object will have an `accep
187187

188188
## Usage with SvelteKit
189189

190+
Formgator can be used in SvelteKit to validate form data and query parameters. Because formgator imports `@sveltejs/kit` internally, you need to bundle it with your application to avoid weird runtime behaviors:
191+
192+
- Move `formgator` from `dependencies` to `devDependencies` in your `package.json`.
193+
- Add `ssr: { noExternal: ['formgator'] }` to the root of `vite.config.{js|ts}`.
194+
195+
This will ensure that formgator use the bundled version of `@sveltejs/kit` instead of an external one. This also means that formgator will be tree-shaken in your production build, and no longer imported from `node_modules` at runtime.
196+
190197
### Form actions
191198

192-
`formgator` exposes a SvelteKit adapter that can be used to validate form data in SvelteKit [form actions](https://kit.svelte.dev/docs/form-actions).
199+
Formgator exposes a SvelteKit adapter that can be used to validate form data in SvelteKit [form actions](https://kit.svelte.dev/docs/form-actions).
193200

194201
```ts
195202
// +page.server.ts

0 commit comments

Comments
 (0)