From f038428041ba4cb7cd1129715e51915b3e508d9e Mon Sep 17 00:00:00 2001 From: Gautier Ben Aim Date: Fri, 25 Oct 2024 16:29:18 +0200 Subject: [PATCH] docs: updated sveltekit usage --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bc1b838..82a01f2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Ali, the friendly alligator that guards your forms -# formgator +# Formgator A validation library for JavaScript `FormData` and `URLSearchParams` objects. @@ -187,9 +187,16 @@ If some fields were accepted nonetheless, the `error` object will have an `accep ## Usage with SvelteKit +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: + +- Move `formgator` from `dependencies` to `devDependencies` in your `package.json`. +- Add `ssr: { noExternal: ['formgator'] }` to the root of `vite.config.{js|ts}`. + +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. + ### Form actions -`formgator` exposes a SvelteKit adapter that can be used to validate form data in SvelteKit [form actions](https://kit.svelte.dev/docs/form-actions). +Formgator exposes a SvelteKit adapter that can be used to validate form data in SvelteKit [form actions](https://kit.svelte.dev/docs/form-actions). ```ts // +page.server.ts