{"id":28517182,"url":"https://github.com/tomjs/vue-cli-plugin-mock","last_synced_at":"2025-07-06T00:32:49.781Z","repository":{"id":294006931,"uuid":"985740972","full_name":"tomjs/vue-cli-plugin-mock","owner":"tomjs","description":"vue cli 的 mock 插件","archived":false,"fork":false,"pushed_at":"2025-05-19T11:22:50.000Z","size":155,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-09T04:42:57.886Z","etag":null,"topics":["mock","vue","vue-cli"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-18T12:36:24.000Z","updated_at":"2025-05-19T11:23:06.000Z","dependencies_parsed_at":"2025-05-18T12:51:44.826Z","dependency_job_id":"419e13ad-4536-4559-ada2-e1e1512228ed","html_url":"https://github.com/tomjs/vue-cli-plugin-mock","commit_stats":null,"previous_names":["tomjs/vue-cli-plugin-mock"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tomjs/vue-cli-plugin-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvue-cli-plugin-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvue-cli-plugin-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvue-cli-plugin-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvue-cli-plugin-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomjs","download_url":"https://codeload.github.com/tomjs/vue-cli-plugin-mock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomjs%2Fvue-cli-plugin-mock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263832104,"owners_count":23517344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["mock","vue","vue-cli"],"created_at":"2025-06-09T04:36:33.871Z","updated_at":"2025-07-06T00:32:49.738Z","avatar_url":"https://github.com/tomjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @tomjs/vue-cli-plugin-mock\n\n[![npm](https://img.shields.io/npm/v/@tomjs/vue-cli-plugin-mock)](https://www.npmjs.com/package/@tomjs/vue-cli-plugin-mock) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vue-cli-plugin-mock) ![NPM](https://img.shields.io/npm/l/@tomjs/vue-cli-plugin-mock)\n\n**English** | [中文](./README.zh_CN.md)\n\n\u003e Provide mock for [Vue CLI](https://cli.vuejs.org/)\n\nThis plugin is modified from [vite-plugin-mock](https://github.com/vbenjs) by [vben](https://github.com/vbenjs/vite-plugin-mock). Most of the code comes from this project. I also use this plugin in my project. Thank you very much.\n\nThis project supports the requirement `\"@vue/cli-service\": \"^5.0.0\"`, and supports `ts` and `js` to write `mock` data\n\n## Install\n\n```bash\n# pnpm\npnpm add @tomjs/vue-cli-plugin-mock -D\n\n# yarn\nyarn add @tomjs/vue-cli-plugin-mock -D\n\n# npm\nnpm add @tomjs/vue-cli-plugin-mock -D\n```\n\n## usage\n\nThis plugin is based on the `express@4` middleware. After installation, `Vue CLI` will automatically load the plugin.\n\n### Configuration parameters\n\n```ts\nexport interface MockOptions {\n  /**\n   * mock file path\n   * @default 'mocks'\n   */\n  mockPath?: string;\n  /**\n   * ignore mock file\n   * @default /^_/\n   */\n  ignore?: RegExp | ((fileName: string) =\u003e boolean);\n  /**\n   * watch mock file change\n   * @default true\n   */\n  watch?: boolean;\n  /**\n   * enable mock\n   * @default true\n   */\n  enable?: boolean;\n  /**\n   * enable logger\n   * @default false\n   */\n  logger?: boolean;\n}\n```\n\n### Use the Configuration File\n\nChoose the configuration method according to your preference.\n\n#### config file\n\nCreate a `mock.config.{json|js|ts|mjs|cjs}` file in the project root directory according to `\"type\":\"commonjs\"` or `\"type\":\"module\"` in `package.json`.\n\n`mock.config.js` example:\n\n```js\n/**\n * @type {import('@tomjs/vue-cli-plugin-mock').MockOptions}\n */\nexport default {\n  logger: true,\n};\n```\n\n#### package.json\n\nAdd `\"mock\"` configuration item to package.json\n\n```json\n{\n  \"mock\": {\n    \"logger\": true\n  }\n}\n```\n\n#### vue.config.js\n\nAdd `mock` configuration item in `pluginOptions`\n\n```js\nmodule.exports = {\n  pluginOptions: {\n    mock: {\n      logger: true,\n    },\n  },\n};\n```\n\n### mock example\n\nmocks/demo1.js\n\n```ts\nexport default [\n  {\n    url: '/mock/demo1/get',\n    method: 'get',\n    response: () =\u003e {\n      return {\n        code: 500,\n        data: 'Bearer 123456789',\n      };\n    },\n  }\n];\n```\n\nmocks/demo2.ts\n\n```ts\nimport { MockMethod } from '@tomjs/vue-cli-plugin-mock';\n\nconst routes: MockMethod[] = [\n  {\n    url: 'get',\n    method: 'get',\n    response: () =\u003e {\n      return {\n        code: 500,\n        data: 'Bearer 123456789',\n      };\n    },\n  },\n  {\n    url: '404',\n    rawResponse: (req, res) =\u003e {\n      res.status(404).send(\n        JSON.stringify({\n          code: 404,\n          msg: '404 Not Found',\n        })\n      );\n    },\n  },\n  {\n    url: '500',\n    rawResponse: (req, res) =\u003e {\n      res.status(500).send({\n        code: 500,\n        msg: '500 Server Error',\n      });\n    },\n  },\n];\n\nexport default routes.map(s =\u003e ({\n  ...s,\n  timeout: Math.random() * 300,\n  url: `/mock/demo2/${s.url}`,\n  method: s.method || 'get',\n})) as MockMethod[];\n```\n\n## Examples\n\n- [vue-ts](./examples/vue-ts)\n- [vue-js](./examples/vue-js)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomjs%2Fvue-cli-plugin-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomjs%2Fvue-cli-plugin-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomjs%2Fvue-cli-plugin-mock/lists"}