{"id":16073361,"url":"https://github.com/wjchumble/vite-plugin-async-catch","last_synced_at":"2025-03-18T05:31:21.133Z","repository":{"id":57393067,"uuid":"367543743","full_name":"WJCHumble/vite-plugin-async-catch","owner":"WJCHumble","description":"A vite plugin that can auto inject try catch code for async function.","archived":false,"fork":false,"pushed_at":"2021-08-19T14:08:54.000Z","size":184,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T16:53:58.324Z","etag":null,"topics":["async-function","try-catch","vite-plugin"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/vite-plugin-async-catch","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/WJCHumble.png","metadata":{"files":{"readme":"README-CN.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":"2021-05-15T05:02:58.000Z","updated_at":"2023-04-11T12:49:34.000Z","dependencies_parsed_at":"2022-09-15T02:21:43.336Z","dependency_job_id":null,"html_url":"https://github.com/WJCHumble/vite-plugin-async-catch","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WJCHumble%2Fvite-plugin-async-catch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WJCHumble%2Fvite-plugin-async-catch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WJCHumble%2Fvite-plugin-async-catch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WJCHumble%2Fvite-plugin-async-catch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WJCHumble","download_url":"https://codeload.github.com/WJCHumble/vite-plugin-async-catch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243903176,"owners_count":20366437,"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":["async-function","try-catch","vite-plugin"],"created_at":"2024-10-09T08:06:57.328Z","updated_at":"2025-03-18T05:31:16.892Z","avatar_url":"https://github.com/WJCHumble.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## vite-plugin-async-catch\n\n一个可以自动为 `async` 函数注入 `try catch` 代码的 Vite 插件。Inspried by [async-catch-loader](https://github.com/yeyan1996/async-catch-loader).\n\n支持在以下类型的项目中使用:\n\n- vue3\n- vue2\n- react\n- vannila js\n\n## 使用\n\n安装:\n\n```bash\nnpm i vite-plugin-async-catch -D\n```\n\n添加插件到 `vite.config.ts`(或者 `vite.config.js`)。\n\n在 Vue3 项目中:\n\n```typescript\nimport { defineConfig } from \"vite\";\nimport vue from \"@vitejs/plugin-vue\";\nimport AsyncCatch from \"vite-plugin-async-catch\";\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    AsyncCatch({\n      catchCode: `console.error(e)`,\n    }),\n  ],\n});\n```\n\n在 Vue2 项目中:\n\n```javascript\nimport { defineConfig } from \"vite\";\nimport { createVuePlugin } from \"vite-plugin-vue2\";\nimport AsyncCatch from \"vite-plugin-async-catch\";\n\nexport default defineConfig({\n  plugins: [\n    createVuePlugin(),\n    AsyncCatch({\n      catchCode: `console.error(e)`,\n    }),\n  ],\n});\n```\n\n在 React 项目中:\n\n```typescript\nimport reactRefresh from \"@vitejs/plugin-react-refresh\";\nimport { defineConfig } from \"vite\";\nimport AsyncCatch from \"vite-plugin-async-catch\";\n\nexport default defineConfig({\n  plugins: [\n    reactRefresh(),\n    AsyncCatch({\n      catchCode: `console.error(e)`,\n    }),\n  ],\n});\n```\n\n## Options\n\n`Options` 的类型定义:\n\n```typescript\ninterface Options {\n  catchCode: string;\n  identifier?: string;\n  finnallyCode?: any;\n}\n```\n\n其中，每个参数的意义:\n\n| 名称         | 介绍                    | 类型   | 默认值           |\n| ------------ | ----------------------- | ------ | ---------------- |\n| catchCode    | 在 catch 代码块中使用   | string | console.error(e) |\n| identifier   | catch 代码块的错误参数  | string | e                |\n| finnallyCode | 在 finally 代码块中使用 | string | null             |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwjchumble%2Fvite-plugin-async-catch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwjchumble%2Fvite-plugin-async-catch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwjchumble%2Fvite-plugin-async-catch/lists"}