Mocky Balboa and Vite
How to use Mocky Balboa with Vite.
Supported versions
≥ 6.0.0
Installation
- pnpm
- npm
- yarn
bash pnpm add -D @mocky-balboa/vite
bash npm install -D @mocky-balboa/vite
bash yarn 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}
- TypeScript
- JavaScript
// vite.config.ts
import { defineConfig } from "vite";
import mockyBalboa from "@mocky-balboa/vite";
export default defineConfig({
plugins: [mockyBalboa()],
});
// vite.config.js
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
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.
- TypeScript
- JavaScript
// vite.config.ts
import { defineConfig } from "vite";
import mockyBalboa from "@mocky-balboa/vite";
export default defineConfig(({ mode }) => ({
plugins: [mockyBalboa({ enabled: mode !== "test" })],
}));
// vite.config.js
import { defineConfig } from "vite";
import mockyBalboa from "@mocky-balboa/vite";
export default defineConfig(({ mode }) => ({
plugins: [mockyBalboa({ enabled: mode !== "test" })],
}));