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

@ztjy/mock-webpack-plugin

v1.0.0

Published

webpack-plugin插件,用于生成mock数据

Downloads

4

Readme

webpack-plugin生成mock数据

期望功能

1:支持多项目✔

2:多前缀配置✔(支持独立api、独立文件夹配置)

3:api做兜底✔

4:切换不同场景数据✔

5:支持本地合并生成的mock数据✔

设计原则

| 数据形式 | 说明 | 优先级 | 禁用方式 | | -------- | ------------------ | ------ | ------------------- | | local | 本地mock文件 | 1 | {disableMock: true} | | yapi | yapi生成的mock数据 | 2 | {disableMock: true} | | server | api的兜底 | 3 | 不传 proxy |

考虑

1.mock数据生成方式
本地文件方式: {
  优点: 方便基于生成的mock修改
  缺点:1:本地文件需要维护
       2:第二次生成时会被覆盖
       3:本地合并生成的mock数据时还是需要生成一份express数据
}

express方式:{
  优点:不生成本地文件,
  缺点:不方便基于生成的mock修改(功能.5可优化)
}

综上所述:使用express方式
2.数据格式
new MockWebpackPlugin({
delay: 800,
mockLocalPath: './mock/index.js',
proxy: {
  '/dspManageServer': 'http://alpha-api-ad.szy.com/dspManageServer',
  '/Upload/imgFile': 'http://alpha-admin-ztjy.szy.com/Upload/imgFile',
},
yapiConfig: [{
  projectId: 633, // 关联的ypai项目id(必传)
  token:  '1f41d9e0f188ec7aaae786cd4663766f4d11fc8a65fbedf08af234234b3dbe90', // 关联的yapi项目token(必传)
  prefix: '/api/member', // 未被 prefixApi | prefixDir命中,则使用该前缀
  proxy: 'http://dev-api-ad.szy.net/dspBusinessServer',
},{
  projectId: 633, // 关联的ypai项目id(必传)
  token:  '1f41d9e0f188ec7aaae786cd4663766f4d11fc8a65fbedf08af234234b3dbe90', // 关联的yapi项目token(必传)
  prefix: '/api/member', // 未被 prefixApi | prefixDir命中,则使用该前缀
}]
})

| 参数 | 说明 | 类型 | 默认 | | ------------- | -------------------- | ------------------------- | ---- | | yapiConfig | yapi配置 | yapiType | | | delay | 请求返回时长 | number | 1000 | | mockLocalPath | 本地已有mock文件入口 | string | | | proxy | 代理转发 | key: string | |

yapiType类型

| 参数 | 说明 | 类型 | 必传 | | -------------------- | ---------------------------- | ----------- | ---- | | projectId | yapi项目id | number | 是 | | token | yapi项目token | string | 是 | | proxy | 兜底api-没有mock数据走proxy | string | 否 | | prefix | api访问前缀 | string | 是 |

3.本地Mock合并
Mock({
// method   完整路径
  'POST /api/member/proxy/auth/registerr': {
    delay: 1200,
    disableMock: true, // 是否禁用mock
    mergeYapi: true, // 是否合并yapi生成的mock数据
    mock: 'a', // 手动mock数据  使用scenes ‘a’里的数据
    mocks: {
      'a': {
        res: {

        },
        mergeYapi: false, // 是否合并yapi生成的mock数据
      },
      'b': {
        res: {

        }
      },
    }
  },
})