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

vite-plugin-swagger-mock

v0.0.1

Published

A mock plugin for vite and compatible with swagger3

Downloads

1

Readme

vite-plugin-swagger-mock

vite 的数据模拟插件,是基于 vite.js 开发的。 并同时支持 swagger、参数校验等功能,通过 mockjs 模拟线上真实接口。

安装 (yarn or npm)

yarn add vite-plugin-swagger-mock -D
# or
npm i vite-plugin-swagger-mock -D

使用

  • vite.config.ts 配置
import { viteSwaggerMock } from "vite-plugin-swagger-mock";
export default () => {
  return {
    plugins: [
      viteSwaggerMock({
        // 配置参数
      }),
    ],
  };
};
  • viteSwaggerMock 配置
{
  // swagger 文档地址
  swaggerUrl?: string
  // 后端接口前缀
  apiPrefix?: string
  // 是否导出 mock 数据
  exportFile?: boolean
  // 导出的文件路径
  docPath?: string
  // 导出的文件名
  docFileName?: string
  // 不需要处理的接口
  exclude?: string[]
  // 接口成功 code 值
  successCode?: number
  // 接口失败 code 值
  errorCode?: number
  // 随机生成数组的条数
  arrayRandom?: number
  // 重启服务时是否重新生成 mock 文件
  override?: boolean
  // 是否开启 mock 服务
  mockEnabled?: boolean
  // mockjs 自定义配置
  mockFunc?: MockFunc
  // 是否在控制台输出变更 mock 日志
  logger?: boolean
  // 是否校验接口参数
  validParams?: boolean
}

mockFunc

用户可以自定义生成 mock 规则,其中包含 string、integer、boolean 类型 default

mockFunc: {
  string: "@csentence()",
  integer: "@integer(1, 100)",
  boolean: "@boolean()",
},

注意事项

  • 在使用本地 mock 文件模拟接口需关闭系统 package.json 文件中的 type:module,否则无法读取到 mock file 文件中导出内容
  • mock 需勿开启请求接口的域名,否则无法监听到本地接口,通过这特性可以在业务中自定义实现单个接口的 mock 开关