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-mockjs-server

v0.0.3

Published

用于vite dev时,进行模拟 api

Downloads

6

Readme

安装

npm install vite-plugin-mockjs-server -D

说明

在vite中使用mockjs 服务
只能在开发模式中使用,无法再打包时构建进项目
需要指定api文件存放目录且按照文件path的方式作为mock接口路径
接口文件命名方式 
[请求方式]_{接口名称}.[文件扩展名]
[get|post|delete]_{name}.[json|ts|js]
内容为接口返回内容,ts|js 中可做一些更复杂的数据生成同时
ts|js 文件中,必须为 module.exports = {content}
不能返回函数
同名的文件,按照 json ts js 的顺序优先级取第一个,应当避免同名文件

举例
当有一个 get 接口为  /test/t
在项目中mockapi地址为   /[mockDir]/test/get_t.[json|ts|js]
mockDir 为相对于vite项目根目录的 mockApi 文件目录。


配置

// vite.config.ts

import vitePluginMockjsServer from 'vite-plugin-mockjs-server'

export default defineConfig({
    plugins: [
        vitePluginMockjsServer({mockDir:"mock"})
    ]
});

选项说明

| 字段 | 类型 | 默认值 | 说明 | | ----| ---- | ---- | ---- | | mockDir | 字符串 | mock |相对于vite项目根目录的 mockApi 文件目录 |

列子

将mockapi目录配置为mock

-mock
--test
---get_a.json
---get_b.ts
---post_c.js

访问地址 get mock/test/a 
 post mock/test/b  
 post mock/test/c
{
  "get_a.json": "内容"
}
module.exports=[
    {
        "ts文件":"测试"
    }
]
module.exports=[
    {
        "js文件":"测试"
    }
]