vite-plugin-imock
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

vite-plugin-imock

Feature

Mock data using vite devServer w/ mockjs syntax supported!

Options

 IMockOptions {
  /**
   *  mock目录名
   * @default mocker
   */
  dirName?: string
  /**
   * 接口前缀名
   * @default /api
   */
  prefix?: string
  /**
   * 路径的根目录
   * @default process.cwd()
   */
  root?: string
}

Usage

// vite.config.js

import { defineConfig } from 'vite'
import Mocker from 'vite-plugin-imock'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [Mocker()],
})


// mocker/api/test.js
module.exports = () => ({
  'data': 'hello world',
  'mockjs|2': [{ // mock syntax supported
    test: 1,
  }],
})

// main.js
fetch('/api/test').then(res => res.json()).then(data => console.log(data))
// {data: 'hello world',mockjs:[{test:1},{test:1}]}

Readme

Keywords

Package Sidebar

Install

npm i vite-plugin-imock

Weekly Downloads

17

Version

0.0.4

License

MIT

Unpacked Size

9.74 kB

Total Files

16

Last publish

Collaborators