{"id":20764680,"url":"https://github.com/yunyoujun/unplugin-mockery","last_synced_at":"2025-04-30T08:50:01.866Z","repository":{"id":260253652,"uuid":"821357590","full_name":"YunYouJun/unplugin-mockery","owner":"YunYouJun","description":"😛 Let's manage your mock.","archived":false,"fork":false,"pushed_at":"2024-11-09T11:37:45.000Z","size":1323,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-17T03:25:55.482Z","etag":null,"topics":["mockery","unplugin"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/unplugin-mockery","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/YunYouJun.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["YunYouJun"]}},"created_at":"2024-06-28T11:07:12.000Z","updated_at":"2024-11-09T11:37:46.000Z","dependencies_parsed_at":"2024-10-30T11:55:21.682Z","dependency_job_id":"4a8e68f6-f7ad-4d97-bf30-83c75036ecb5","html_url":"https://github.com/YunYouJun/unplugin-mockery","commit_stats":null,"previous_names":["yunyoujun/unplugin-mockery"],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Funplugin-mockery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Funplugin-mockery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Funplugin-mockery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YunYouJun%2Funplugin-mockery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YunYouJun","download_url":"https://codeload.github.com/YunYouJun/unplugin-mockery/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225028977,"owners_count":17409614,"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":["mockery","unplugin"],"created_at":"2024-11-17T10:53:18.477Z","updated_at":"2024-11-17T10:53:19.059Z","avatar_url":"https://github.com/YunYouJun.png","language":"TypeScript","readme":"# unplugin-mockery\n\n[![NPM version](https://img.shields.io/npm/v/unplugin-mockery)](https://www.npmjs.com/package/unplugin-mockery)\n\n[Preview Usage Video](https://github.com/YunYouJun/unplugin-mockery/discussions/3)\n\n## Features\n\n- Vue CLI (webpack)\n- Vite\n- Hot Reload Routes\n\n## Why unplugin-mockery?\n\n- A visual mock management devtool.\n- We have some old projects that need to be compatible with Vue CLI and Vite.\n\n## Install\n\n```bash\npnpm add -D unplugin-mockery\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eVite\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// vite.config.ts\nimport Mocker from 'unplugin-mockery/vite'\n\nexport default defineConfig({\n  plugins: [\n    Mocker({ /* options */ }),\n  ],\n})\n```\n\nExample: [`playground/`](./playground/)\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eRollup\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// rollup.config.js\nimport Mocker from 'unplugin-mockery/rollup'\n\nexport default {\n  plugins: [\n    Mocker({ /* options */ }),\n  ],\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWebpack\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// webpack.config.js\nmodule.exports = {\n  /* ... */\n  plugins: [\n    require('unplugin-mockery/webpack').default({ /* options */ })\n  ]\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eNuxt\u003c/summary\u003e\u003cbr\u003e\n\n```ts\nexport default defineNuxtConfig({\n  modules: [\n    'unplugin-mockery/nuxt',\n  ],\n\n  unpluginMockery: {\n    mockDir,\n    client: {\n      port: 51223,\n    },\n  },\n})\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVue CLI\u003c/summary\u003e\u003cbr\u003e\n\n在 Webpack 中，它工作地很好。\n但在 Vue Cli 中，`webpack-dev-server` 的启动时机有所不同，因此我们无法通过插件获取 Vue Cli 中的 `webpack-dev-server` `devServer` 的实例。\n而是通过获取 webpack 的方式进行设置。\n\nIn Webpack, it works well.\nBut in Vue Cli, the timing of starting `webpack-dev-server` is different, so we cannot get the instance of `webpack-dev-server` `devServer` in Vue Cli through the plugin.\nInstead, we set it by `getWebpackConfig`.\n\n```ts\n// vue.config.js\nconst { getWebpackConfig } = require('unplugin-mockery/webpack')\n\nmodule.exports = {\n  configureWebpack: {\n    devServer: {\n      ...getWebpackConfig({ /* options */ }).devServer,\n    },\n  },\n}\n```\n\n```bash\n# .env custom client port\nVUE_APP_MOCKERY_CLIENT_PORT=51224\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eesbuild\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// esbuild.config.js\nimport { build } from 'esbuild'\nimport Mocker from 'unplugin-mockery/esbuild'\n\nbuild({\n  plugins: [Mocker()],\n})\n```\n\n### Schema Setting in VSCode\n\nEdit `.vscode/settings.json`:\n\n```json\n{\n  // schema\n  \"json.schemas\": [\n    {\n      \"fileMatch\": [\"*.scene.json\"],\n      \"url\": \"./mock/schemas/scene.schema.json\"\n    }\n  ]\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n## Development\n\n```bash\n# run template\n\n# for vue-cli(webpack)\npnpm play:vue-cli\n\n# for webpack\npnpm play:webpack\n\n# for vite\npnpm play:vite\n```\n\n## Options\n\n```ts\nexport interface Options {\n  /**\n   * Base URL for inspector UI\n   *\n   * @default read from Vite's config\n   */\n  base?: string\n\n  // define your plugin options here\n  /**\n   * Display debug information.\n   */\n  debug?: boolean\n\n  /**\n   * The directory where the mock files are located.\n   * @default 'mock'\n   * mock/api: mock files\n   * mock/scenes: scene files\n   * mock/schemas: schema file\n   *   scene.schema.json: scene schema file\n   *   config.schema.json: config schema file\n   * mock/utils: utility files\n   * mock/config.json: configuration file\n   */\n  mockDir: string\n\n  /**\n   * mock client ui\n   */\n  client?: {\n    /**\n     * enable client\n     * @default true\n     */\n    enable?: boolean\n    /**\n     * The port to run the client server.\n     */\n    port?: number\n    /**\n     * auto open browser.\n     */\n    open?: boolean\n  }\n}\n```\n\n## Todo\n\n- filename as url when url not set\n- click settings icon show config in dialog\n- 添加 UI 创建场景合集功能\n","funding_links":["https://github.com/sponsors/YunYouJun"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyunyoujun%2Funplugin-mockery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyunyoujun%2Funplugin-mockery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyunyoujun%2Funplugin-mockery/lists"}