Giter VIP home page Giter VIP logo

vite-plugin-faker's Introduction

vite-plugin-faker

English | 简体中文

✨ Features

  • 📦 Offline mock tool out of the box

  • 😛 Define the return value through the interface Interface automatically generates mock data

  • 📄 Support generating mock files for secondary editing

  • 🔥 Support hot update, only update the changed part

📦 Installation

yarn add -D vite-plugin-faker
npm install vite-plugin-faker --save-dev

🔨 Example

Add configuration in vite.config.ts

import vitePluginFaker from 'vite-plugin-faker';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: {
    vitePluginFaker({
      basePath: 'src/apis',
      mockDir: '/mock',
      includes: [/^.Service/],
      watchFile: true
    })
  }
});

Note: If you need to use this plugin to generate mock data, Please keep consistent with the requsest structure of the playground. Or the following two points are satisfied:

  • GET or POST accepts a generic return value, the first parameter of the method is url

  • GET or POST calls a general request method, the second parameter of the general request method is the general backend return body type

⚙️ Configuration items

-basePath: The root directory to be parsed, with the project directory as the root directory

-includes: The class name rules to be parsed, you can set a regular expression or an array of regular expressions

-excludes and includes are mutually exclusive, meaning type rules not to be parsed, generally not used

-watchFile: Whether to monitor file changes, when it is true, mock data will be automatically updated when the file changes

-mockDir: Set the mock file storage location. If it is not set, the mock file will not be generated, that is, it will be read from the memory every time

📛 Mock.json extra fields

You can customize your request in the generated mock.json

{
  // Interface response time
  "timeout": 200,
  // The corresponding Http status code of the interface
  "httpCode": 401
}

📁 Workflow

workflow

vite-plugin-faker's People

Contributors

jserwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vite-plugin-faker's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.