Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iodigital/vite-plugin-msw

Package Overview
Dependencies
Maintainers
5
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iodigital/vite-plugin-msw

Mock Service Worker browser and node integration for Vite

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

@iodigital/vite-plugin-msw

Mock Service Worker browser and node integration for Vite.

Usage

Install

npm install --save-dev @iodigital/vite-plugin-msw
# yarn add --dev @iodigital/vite-plugin-msw
# pnpm add --save-dev @iodigital/vite-plugin-msw

Define mocks

https://mswjs.io/docs/getting-started/mocks

Add to Vite config

// Import plugin
import msw from "@iodigital/vite-plugin-msw";

// Import msw handlers
import { handlers } from "../mocks/handlers";

// Pass them to plugin
export default defineConfig({
  plugins: [msw({ handlers })],
});

Config

interface VitePluginMswOptions {
  handlers: RequestHandler[];
  mode?: "browser" | "node";
  build?: boolean;
}

Handlers

  • Required

MSW handlers. More information on how to define these: https://mswjs.io/docs/getting-started/mocks

Mode

  • Optional
  • Default: browser
Browser

To start MSW in the client, please follow the Configure worker step and Start worker step in the MSW docs. The mockServiceWorker.js file will be provided by the Vite Dev Server.

Node

This will handle the mocked service worker handlers via a Vite Dev Server plugin.

Build

  • Optional
  • Default: false

A true value will output MSW's mockServiceWorker.js file to the Vite build directory, in case if MSW is needed in production.


Development

npm run dev

Example vite application with plugin

npm run build
cd examples/with-vite
npm run dev
curl http://localhost:3000/api/health

Build

npm run build

Keywords

FAQs

Package last updated on 27 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc