Code Monkey home page Code Monkey logo

test-mock-webpack-plugin's Introduction

Test-Mock-Webpack-Plugin

这个插件提供了一个简单的方式,只需要一点配置,你就可以在基于webpackwebpack-dev-server的项目中轻松的mock数据。

插件当前只支持GET请求的数据mock.

使用

例子

在webpack的配置文件中,加入插件:

const TestMockMockPlugin = require('./lib/index.js')
const path = require('path')

module.exports = {
  // ...
  plugins: [
    // ...
    new TestMockMockPlugin({
      root: path.resolve(__dirname, 'mock'),
      lazy: true,
      autoRefresh: true
    })
  ]
}

具体参考examples里的案例

配置

  • root

    String

    mock文件夹的路径,必须是一个绝对路径

  • lazy

    Boolean

    如果设置成true的话,文件将会在接收到对应请求时被加载,在这种情况下,请求处理时间可能会稍微长一点,但是项目启动的时间相对设置成false时短了。

    如果设置成false的话,项目会在启动的时候就加载好所有的mock文件放入缓存中,所以项目启动时间会有所增加,但是请求的响应速度会加快。

  • autoRefresh

    Boolean

    设置成true的话,只要你修改了mock文件夹下的文件,浏览器都会自动刷新以获取最新的数据。设置成false的话,你只能手动刷新来打到目的。

    注意:这个配置只有在lazy设置成true的时候起作用。如果lazyfalse的话,那么优先会加载缓存,你需要重启项目才能获得更新后的mock数据。

test-mock-webpack-plugin's People

Contributors

gosunadeod avatar

Watchers

 avatar  avatar

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.