Skip to main content

Mocky Balboa and Vite

How to use Mocky Balboa with Vite.

Supported versions

≥ 6.0.0

Installation

bash pnpm add -D @mocky-balboa/vite

Usage

Dev mode

In dev mode, all you need to do is enable the Vite plugin in your vite.config.{ts,js}

// vite.config.ts
import { defineConfig } from "vite";
import mockyBalboa from "@mocky-balboa/vite";

export default defineConfig({
plugins: [mockyBalboa()],
});

For plugin options, see the API reference.

Build mode

It's up to you to integrate the Mocky Balboa server into your built application. See the following guides for common server integrations:

API reference

API reference

Vitest compatibility

If you are sharing your Vite configuration with Vitest, you will need to disable the Mocky Balboa plugin when running in test mode. You can do this in your vite.config.{ts,js} by setting the enabled option to false conditionally.

// vite.config.ts
import { defineConfig } from "vite";
import mockyBalboa from "@mocky-balboa/vite";

export default defineConfig(({ mode }) => ({
plugins: [mockyBalboa({ enabled: mode !== "test" })],
}));