sv community add-on: @msw/sveltekit
Important
Svelte maintainers have not reviewed community add-ons for malicious code. Use at your discretion.
You can create a new SvelteKit project with this add-on using the following command:
npx sv create --add @msw/sveltekitOr integrate MSW add-in into an existing project with this one:
npx sv add @msw/sveltekitmswadded as a dev dependency.src/msw/handlers.tsorsrc/msw/handlers.jswith shared request handlers.- Optional browser setup in
src/msw/browserandsrc/hooks.client. - Optional Node setup in
src/msw/nodeandsrc/hooks.server. - Browser worker configuration in
package.json.
Choose where MSW should run. This is a multiselect option.
Default: browser,node
npx sv add @msw/sveltekit="environments:browser,node"If you enable browser mocking, generate the service worker after installing dependencies:
npx msw init static --save