npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

umi-mock-middleware

v1.0.0

Published

umi-mock-middleware是从umi代码中单独摘取出了mock中间件相关的独立代码,使之可以在React之外的环境,比如Vue中使用。功能更独立,更专一,使用更方便。

Downloads

103

Readme

umi-mock-middleware

项目介绍

​ umi-mock-middleware是从umi代码中单独摘取出了mock中间件相关的独立代码,使之可以在React之外的环境,比如Vue中使用。功能更独立,更专一,使用更方便。

​ 如果想了解更多umijs的信息,请移步umijs官网,同时感谢umi对开源事业的贡献。

安装

npm install umi-mock-middleware

使用

​ 以Vue CLI3为例,首先注册中间件,修改vue.config.js,如果没有在项目根文件夹下新建一个,关键代码如下:

const path = require("path");
const { createMockMiddleware } = require("umi-mock-middleware");

module.exports = {
  devServer: {
    before: app => {
      if (process.env.MOCK !== "none" && process.env.HTTP_MOCK !== "none") {
        app.use(createMockMiddleware());
      }
    }
  }
};

​ 在项目根文件夹下创建 .umirc.mock.js ,示例代码如下:

module.exports = {
  ...require("./mock/index"),
  // 这里可以引入任意的mock文件,位置也随意。
};

​ 在项目根文件夹下创建mock文件夹,在其中创建index.js,位置和文件名无所谓,在 .umirc.mock.js 中引用即可。

module.exports = {
  // 以HTTP动词和URL为Key,映射一个处理句柄。
  [`GET /index`](req, res) {
    // 返回你的mock数据。比如:
    res.json({
        success: true
    })
  }
};

​ 到此你的mock数据已经可以访问了,当修改mock数据的时候,中间件会自动刷新,无需重启。