@zenghj/mini-mock
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

mini-mock

This Project is initialized by saber-cli using "ts-lib" scaffold template. Get more information from saber-cli.

Features

  • Light weight mock tool with local mock files;
  • Automaticly refresh config without restart devServer;

Usage

yarn add @zenghj/mini-mock
// webpack.dev.conf.js
const { mock } = require('@zenghj/mini-mock')
const mockOptionFile = path.resolve(__dirname, '../mock/index')
module.exports = {
  // ...
  devServer: {
    before: function(app, server, compiler) {
      app.use(mock({
        entry: mockOptionFile // mock config file path
      }));
    }
  }
}
// mock/index.js
const path = require("path");
const absolute = relative => path.resolve(__dirname, relative);

module.exports = {
  off: false, // whether turn off mock or not
  routes: { // route map
    // `${HTTP_METHOD}:${API_PATH}`: `${MOCK_FILE_ABSOLUTE_PATH}`
    // API_PATH supports express path rule.
    "GET:/test": absolute("test.json"),
    "GET:/test/:id": absolute("test2.json")
  }
};

For more detail see example

Package Sidebar

Install

npm i @zenghj/mini-mock

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

71.1 kB

Total Files

55

Last publish

Collaborators

  • zenghj