{"id":21296977,"url":"https://github.com/s3xysteak/unplugin-export-collector","last_synced_at":"2025-09-11T09:34:22.320Z","repository":{"id":227507130,"uuid":"771417776","full_name":"s3xysteak/unplugin-export-collector","owner":"s3xysteak","description":"Recursively get all named export from a file and out-of-the-box support unplugin-auto-import","archived":false,"fork":false,"pushed_at":"2024-10-15T15:58:38.000Z","size":492,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-26T14:00:31.241Z","etag":null,"topics":["esm","unplugin","unplugin-auto-import","utils"],"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/s3xysteak.png","metadata":{"files":{"readme":"README-zh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-13T09:08:26.000Z","updated_at":"2025-03-21T14:28:41.000Z","dependencies_parsed_at":"2024-05-03T18:40:18.887Z","dependency_job_id":"c07eacdb-fc83-43c3-8f02-9c84b355808f","html_url":"https://github.com/s3xysteak/unplugin-export-collector","commit_stats":{"total_commits":109,"total_committers":3,"mean_commits":"36.333333333333336","dds":0.08256880733944949,"last_synced_commit":"d22962221499ff61802e57572b76f26355f01cb0"},"previous_names":["s3xysteak/un-auto-import-resolver","s3xysteak/export-collector","s3xysteak/unplugin-export-collector"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/s3xysteak/unplugin-export-collector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s3xysteak%2Funplugin-export-collector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s3xysteak%2Funplugin-export-collector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s3xysteak%2Funplugin-export-collector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s3xysteak%2Funplugin-export-collector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s3xysteak","download_url":"https://codeload.github.com/s3xysteak/unplugin-export-collector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s3xysteak%2Funplugin-export-collector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274609465,"owners_count":25316621,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["esm","unplugin","unplugin-auto-import","utils"],"created_at":"2024-11-21T14:31:27.513Z","updated_at":"2025-09-11T09:34:22.291Z","avatar_url":"https://github.com/s3xysteak.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :tada: unplugin-export-collector\n\n[English](./README.md) | 简体中文\n\n收集ESM所有导出的工具，附带开箱即用的 `unplugin-auto-import` 支持。\n\n## :hammer: Install\n\n```sh\n$ pnpm i -D unplugin-export-collector\n```\n\n## :rocket: 功能\n\n从一个ESM文件中递归的收集所有具名导出。\n\n假设有 `src/index.ts` :\n\n```js\n// src/index.ts\nexport const one = 1\nexport * from './func1' // 从另一个文件导出。\n// export * from '~/func2' // 也支持别名\nexport * from 'vue' // 依赖的重导出将会被忽略。\n```\n\n还有 `src/func1.ts` :\n\n```js\n// src/func1.ts\nfunction func1() {}\nexport { func1 as funcRe }\n```\n\n只是获取所有具名导出:\n\n```js\nimport { expCollector } from 'unplugin-export-collector/core'\n\nconsole.log(await expCollector('./src/index.ts'))\n// ['one', 'funcRe']\n```\n\n或者支持 `unplugin-auto-import`，你可以在下面看到完整说明，这里以Vite为例：\n\n```js\nimport ExportCollector from 'unplugin-export-collector/vite'\n\nexport default defineConfig({\n  plugins: [\n    ExportCollector({ /* options */ }),\n  ],\n})\n```\n\n这会在打包时默认在`./src/imports.js`生成一个文件，你可以将其导出后像这样在项目中使用：\n\n```ts\nimport { defineConfig } from 'vite'\nimport Imports from 'my-project/imports' // 你需要自行处理打包时的导出项\n\nexport default defineConfig({\n  plugins: [\n    AutoImport({\n      imports: [\n        Imports()\n      ]\n    }),\n  ]\n})\n```\n\n同样支持使用resolvers，只需要将选项设置为 `type: 'resolvers'`:\n\n```js\nExportCollector({\n  type: 'resolvers'\n})\n```\n\n在项目中使用：\n\n```ts\nimport { defineConfig } from 'vite'\nimport Resolvers from 'my-project/resolvers'\n\nexport default defineConfig({\n  plugins: [\n    AutoImport({\n      resolvers: [\n        Resolvers()\n      ]\n    }),\n  ]\n})\n```\n\n## :wrench: 使用\n\n\u003e 更多细节见 `test` 文件夹中的单元测试，与 `test/unplugin-lab` 中的示例。\n\n### 生成 autoImport 方法\n\n\u003cdetails\u003e\n\u003csummary\u003eVite\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// vite.config.ts\nimport ExportCollector from 'unplugin-export-collector/vite'\n\nexport default defineConfig({\n  plugins: [\n    ExportCollector({ /* options */ }),\n  ],\n})\n```\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 ExportCollector from 'unplugin-export-collector/rollup'\n\nexport default {\n  plugins: [\n    ExportCollector({ /* options */ }),\n    // other plugins\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-export-collector/webpack').default({ /* options */ }),\n  ],\n}\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 ExportCollector from 'unplugin-export-collector/esbuild'\n\nbuild({\n  /* ... */\n  plugins: [\n    ExportCollector({\n      /* options */\n    }),\n  ],\n})\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n### 选项:\n\n请移步至[类型声明](./src/core/types.ts)，所有选项都带有详细的注释说明。\n\n### 获取具名导出的名称数组\n\n像这样使用 :\n\n```js\nimport { expCollector } from 'unplugin-export-collector/core'\n\nconst val = await expCollector('./src') // 默认情况下基于项目根目录。\n\nconsole.log(val)\n// ['one', 'funcRe']\n```\n\n你也可以自定义base路径。\n\n```js\n// ...\nconst val = await expCollector(\n  './index.ts',\n  {\n    base: fileURLToPath(new URL('./src/', import.meta.url))\n    // alias: { '~': fileURLToPath(new URL('.', import.meta.url)) } // 也支持别名\n  }\n)\n// 结果将会和上面的例子相同。\n```\n\n`core` 中暴露了一系列方法，这里只做简短的说明：\n\n- `expGenerator` 读取文件，生成autoImport方法并写入\n- `expGeneratorData` 读取文件但不写入，返回autoImport方法的字符串\n- `expCollector` 读取文件，返回具名导出数组\n- `parser` 读取字符串，返回一层的具名导出数组和重导出路径数组\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs3xysteak%2Funplugin-export-collector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs3xysteak%2Funplugin-export-collector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs3xysteak%2Funplugin-export-collector/lists"}