{"id":28259183,"url":"https://github.com/pangyunchuan/vite-plugin-mockjs-server","last_synced_at":"2026-02-28T17:02:07.349Z","repository":{"id":57393149,"uuid":"463386419","full_name":"pangyunchuan/vite-plugin-mockjs-server","owner":"pangyunchuan","description":"用于vite dev时，进行模拟 api","archived":false,"fork":false,"pushed_at":"2022-10-19T05:08:01.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-01T11:59:35.181Z","etag":null,"topics":["api","mock-api","mockjs","vite","vite-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pangyunchuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-25T03:41:01.000Z","updated_at":"2022-11-07T17:57:47.000Z","dependencies_parsed_at":"2022-09-15T02:40:24.913Z","dependency_job_id":null,"html_url":"https://github.com/pangyunchuan/vite-plugin-mockjs-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pangyunchuan/vite-plugin-mockjs-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangyunchuan%2Fvite-plugin-mockjs-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangyunchuan%2Fvite-plugin-mockjs-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangyunchuan%2Fvite-plugin-mockjs-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangyunchuan%2Fvite-plugin-mockjs-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pangyunchuan","download_url":"https://codeload.github.com/pangyunchuan/vite-plugin-mockjs-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pangyunchuan%2Fvite-plugin-mockjs-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29943662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:49:17.081Z","status":"ssl_error","status_checked_at":"2026-02-28T13:48:50.396Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","mock-api","mockjs","vite","vite-plugin"],"created_at":"2025-05-20T02:16:34.487Z","updated_at":"2026-02-28T17:02:07.338Z","avatar_url":"https://github.com/pangyunchuan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 安装\n\n```text\nnpm install vite-plugin-mockjs-server -D\n\n```\n\n## 说明\n\n```text\n在vite中使用mockjs 服务\n只能在开发模式中使用,无法再打包时构建进项目\n需要指定api文件存放目录且按照文件path的方式作为mock接口路径\n接口文件命名方式 \n[请求方式]_{接口名称}.[文件扩展名]\n[get|post|delete]_{name}.[json|ts|js]\n内容为接口返回内容，ts|js 中可做一些更复杂的数据生成同时\nts|js 文件中,必须为 module.exports = {content}\n不能返回函数\n同名的文件，按照 json ts js 的顺序优先级取第一个,应当避免同名文件\n\n举例\n当有一个 get 接口为  /test/t\n在项目中mockapi地址为   /[mockDir]/test/get_t.[json|ts|js]\nmockDir 为相对于vite项目根目录的 mockApi 文件目录。\n\n\n\n```\n\n## 配置\n\n```typescript\n// vite.config.ts\n\nimport vitePluginMockjsServer from 'vite-plugin-mockjs-server'\n\nexport default defineConfig({\n    plugins: [\n        vitePluginMockjsServer({mockDir:\"mock\"})\n    ]\n});\n```\n\n## 选项说明\n\n|  字段 | 类型  | 默认值  |       说明     |\n|  ----| ---- | ---- | ----                             |\n| mockDir | 字符串 | mock  |相对于vite项目根目录的 mockApi 文件目录 |\n\n## 列子\n```text\n将mockapi目录配置为mock\n\n-mock\n--test\n---get_a.json\n---get_b.ts\n---post_c.js\n\n访问地址 get mock/test/a \n post mock/test/b  \n post mock/test/c\n```\n\n```json\n{\n  \"get_a.json\": \"内容\"\n}\n```\n```typescript\nmodule.exports=[\n    {\n        \"ts文件\":\"测试\"\n    }\n]\n```\n```javascript\nmodule.exports=[\n    {\n        \"js文件\":\"测试\"\n    }\n]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpangyunchuan%2Fvite-plugin-mockjs-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpangyunchuan%2Fvite-plugin-mockjs-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpangyunchuan%2Fvite-plugin-mockjs-server/lists"}