Contributing Guide
February 26, 2026 · View on GitHub
Thank you for your interest in contributing to vite-plugin-mock-dev-server! This document provides guidelines and instructions to help you get started.
English | 简体中文
Table of Contents
- Code of Conduct
- Getting Started
- Development Workflow
- Coding Guidelines
- Commit Convention
- Pull Request Process
- Release Process
Code of Conduct
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
Getting Started
Prerequisites
- Node.js: Version
^20 || >=22 - pnpm: Version
>=10.30.1(this project uses pnpm workspaces) - Git: For version control
Repository Setup
-
Fork the repository
Click the "Fork" button on the GitHub repository page to create your own fork.
-
Clone your fork
git clone https://github.com/YOUR_USERNAME/vite-plugin-mock-dev-server.git cd vite-plugin-mock-dev-server -
Install dependencies
pnpm install -
Verify setup
# Run linting pnpm lint # Run tests pnpm test
Development Workflow
Project Structure
This is a monorepo managed by pnpm workspaces:
vite-plugin-mock-dev-server/
├── vite-plugin-mock-dev-server/ # Core plugin package
│ ├── src/ # Source code
│ │ ├── build/ # Standalone mock server build
│ │ ├── compiler/ # Mock file compiler (esbuild/rolldown)
│ │ ├── cookies/ # Cookie handling
│ │ ├── core/ # Core plugin logic
│ │ ├── helpers/ # Helper functions
│ │ ├── mockHttp/ # HTTP mock middleware
│ │ ├── mockWebsocket/ # WebSocket mock support
│ │ ├── types/ # TypeScript type definitions
│ │ └── utils/ # Utility functions
│ ├── __tests__/ # Unit tests
│ └── package.json
├── docs/ # VitePress documentation site
├── example/ # Example project for testing
├── package.json # Root package.json
└── pnpm-workspace.yaml # pnpm workspace configuration
Development Commands
# Build the plugin
pnpm build
# Start development mode with example project
pnpm dev
# Build example project
pnpm example:build
# Run documentation site in development mode
pnpm docs:dev
# Build documentation site
pnpm docs:build
# Run linting
pnpm lint
# Run tests
pnpm test
# Run tests in watch mode
pnpm test --watch
Running Tests
The project uses Vitest for testing.
# Run all tests
pnpm test
# Run tests with coverage
pnpm test --coverage
# Run tests in watch mode (useful during development)
pnpm test --watch
# Run specific test file
pnpm test src/__tests__/compiler.spec.ts
Debugging
To debug the plugin during development:
-
Using the example project
The
example/directory contains a test project that uses the plugin:pnpm devThis starts the example Vite project with the plugin loaded.
-
Adding debug logs
The project uses the
debugpackage. Enable debug logs:DEBUG=vite-plugin-mock-dev-server pnpm dev -
VS Code debugging
Create a
.vscode/launch.jsonfile:{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug Example", "runtimeExecutable": "pnpm", "runtimeArgs": ["dev"], "cwd": "${workspaceFolder}", "console": "integratedTerminal" } ] }
Coding Guidelines
Code Style
This project uses ESLint with @pengzhanbo/eslint-config for code linting.
# Check code style
pnpm lint
# Auto-fix linting issues
pnpm lint -- --fix
Key style rules:
- Use single quotes for strings
- No trailing semicolons
- 2 spaces indentation
- Maximum line length: 120 characters
TypeScript Guidelines
- Strict mode enabled: All code must be type-safe
- Explicit return types: Public APIs should have explicit return type annotations
- No
any: Avoid usinganytype; useunknownwith type guards when necessary
JSDoc Documentation
All public APIs must include JSDoc comments in the following format:
/**
* English description
*
* 中文描述
*
* @param paramName - English description / 中文描述
* @returns English description / 中文描述
* @example
*/
Example:
/**
* Define mock data that can be shared across multiple mock files
*
* 定义可在多个 mock 文件间共享的 mock 数据
*
* @param key - Unique identifier for the data / 数据的唯一标识符
* @param initialData - Initial value of the data / 数据的初始值
* @returns A mock data object with getter, setter, and value properties / 包含 getter、setter 和 value 属性的 mock 数据对象
* @example
* ```ts
* export default defineMockData('posts', [])
* ```
*/
export function defineMockData<T>(key: string, initialData: T): MockData<T>
Commit Convention
We follow the Angular Commit Convention. Each commit message should follow this format:
<type>(<scope>): <subject>
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, semicolons, etc.)refactor: Code refactoringperf: Performance improvementstest: Adding or updating testsbuild: Build system changesci: CI/CD changeschore: Other changes
Examples:
feat(compiler): add support for json5 files
fix(http): resolve cookie parsing issue
docs: update API documentation
Pull Request Process
-
Create a branch
git checkout -b feat/your-feature-name # or git checkout -b fix/your-bug-fix -
Make your changes
- Write clear, concise code
- Add tests for new features
- Update documentation if needed
- Ensure all tests pass
-
Commit your changes
git add . git commit -m "feat(scope): your commit message" -
Push to your fork
git push origin feat/your-feature-name -
Create a Pull Request
- Go to the original repository on GitHub
- Click "New Pull Request"
- Select your fork and branch
- Fill in the PR template with:
- Clear description of changes
- Related issue numbers (if any)
- Screenshots (if UI changes)
-
PR Review
- Maintainers will review your PR
- Address any requested changes
- Once approved, your PR will be merged
Release Process
Note: Only maintainers can perform releases.
The project uses bumpp for version management and conventional-changelog for changelog generation.
# Bump version, generate changelog, commit, tag, and push
pnpm release
# Publish to npm
pnpm release:publish
Questions?
If you have any questions or need help, feel free to:
- Open an issue
- Start a discussion
Thank you for contributing! 🎉