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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mockup-webpack-plugin

v1.1.2

Published

<div> <h1>Mockup Webpack Plugin</h1> </div>

Downloads

29

Readme

  npm i --save-dev mockup-webpack-plugin

1. 在webpack.config.js的plugins配置项中加入MockupWebpackPlugin

const MockupWebpackPlugin = require('mockup-webpack-plugin')

module.exports = {
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js'
  },
  plugins: [
    new MockupWebpackPlugin()
  ]
}

2. 在webpackDevServer.config配置代理

module.exports = function(proxy, allowedHost) {
  return {
    proxy: {
      '/api': {
        target: 'http://localhost:7200',
        pathRewrite: {
          '^/api' : ''
        }
      }
    }
  };
}

3. 在根目录下新建插件的配置文件:mockup.config.json

| Name | Type | Required | Description | | :---------------: | :---------: | :------: | ------------------------------------------------------------ | | port | {number} | Y | 代理服务器的端口,与webpackDevServer.config中proxy.target一致 | | env | {string} | N | dev/online,只有在dev下才能dump静态mock文件
| mode | {String} | N | dev/online,请求接口时,响应数据的来源 | exemptionList | {Array} | N | 白名单 | openSchema | {Boolean} | N | 是否对请求、响应数据进行类型检验 | | proxy | {Object} | Y | 代理配置项 |

Options.proxy

dev/online:

| Name | Type | Required | Description | | :----------: | :--------: | :------: | ------- | | pid | {number} | Y | product_id,工程id | | token | {String} | Y | | | target | {String} | Y | 需要转发的目标路径 |

example

| port | 7200 | | ------ | ------------------------------------------------------------ | | pid | 2415 | | token | ee1c1fbb547e07fdb2bca1ad7650c6b3188ed976390e6eb311cc01249123c30c | | target | http://yapi.baidu-int.com/mock |

{
  "port": 7200,
  "env": "dev",
  "mode": "online",
  "exemptionList": [
    "/bmc/data/account/disable"

  ],
  "proxy": {
    "online": {},
    "dev": {
      "pid": 2415,
      "token": "ee1c1fbb547e07fdb2bca1ad7650c6b3188ed976390e6eb311cc01249123c30c",
      "target": "http://yapi.baidu-int.com/mock"
    }
  }
}

描述:

  1. proxy['env']必须存在;
  2. env=dev,且本地mockup文件不存在时,会自动dump文件;
  3. mode和exemptionList的配合使用,如:mode='online',存在于exemptionList中的请求会读取本地json文件里的数据作为Response,而不存在的则会访问线上接口获取响应;

1.0.1 初始版本

1.0.2 增加代理功能:支持手动选择数据来源(Yapi、本地)

1.0.4 增加Response Schema校验

1.1.1

①将webpackPlugin.options抽离为单独的配置文件,即:mockup.config.json;

②增加Request Query、Response Body校验;

③增加mock schema校验开关(暂未开启);