{"id":50457378,"url":"https://github.com/markmals/vite-plugin-component-lib","last_synced_at":"2026-06-01T03:04:58.464Z","repository":{"id":323086832,"uuid":"1092082350","full_name":"markmals/vite-plugin-component-lib","owner":"markmals","description":null,"archived":false,"fork":false,"pushed_at":"2025-11-08T01:00:35.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-08T03:04:59.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markmals.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-08T00:59:16.000Z","updated_at":"2025-11-08T01:00:39.000Z","dependencies_parsed_at":"2025-11-08T03:05:54.486Z","dependency_job_id":null,"html_url":"https://github.com/markmals/vite-plugin-component-lib","commit_stats":null,"previous_names":["markmals/vite-plugin-component-lib"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/markmals/vite-plugin-component-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmals%2Fvite-plugin-component-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmals%2Fvite-plugin-component-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmals%2Fvite-plugin-component-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmals%2Fvite-plugin-component-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markmals","download_url":"https://codeload.github.com/markmals/vite-plugin-component-lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markmals%2Fvite-plugin-component-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33757791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"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":[],"created_at":"2026-06-01T03:04:44.880Z","updated_at":"2026-06-01T03:04:58.457Z","avatar_url":"https://github.com/markmals.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## vite-plugin-component-lib\n\nFramework-agnostic Vite plugin that emits an unbundled component library in both ESM and CJS formats by default, using a single `vite build` command. It wires up Vite’s `environments` + `builder` APIs so the same source can ship to multiple module targets without hand-rolled Rollup/Rolldown configs.\n\n### Why use it?\n\n- Dual-format output with preserved modules, so consumers can tree-shake from either `dist/esm` or `dist/cjs`\n- Sensible defaults for externals: every bare import is treated as external unless you explicitly keep it internal\n- Works for any UI stack (React, Vue, Svelte, Solid, Lit, etc.) because it never assumes a renderer; you can bring your own Vite plugins\n\n\u003e [!IMPORTANT]\n\u003e Requires Vite 6+ for the Environment API\n\n## Installation\n\n```bash\nnpm add -D vite-plugin-component-lib\n```\n\n## Quick start\n\n```ts\n// vite.config.ts\nimport { defineConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\nimport { components } from \"vite-plugin-component-lib\";\n\nexport default defineConfig({\n    plugins: [react(), components()],\n});\n```\n\nRun `vite build`. The plugin:\n\n1. Creates two environments (`esm` and `cjs` by default).\n2. Uses Vite’s builder to run them sequentially in one command.\n3. Emits preserved modules into `dist/esm` and `dist/cjs` with matching folder structures.\n4. Generates declaration files via [unplugin-dts](https://github.com/qmhc/unplugin-dts) and writes them to `dist`.\n\n## Output layout\n\n```\ndist/\n├─ esm/\n│  ├─ index.js\n│  └─ components/Button.js\n└─ cjs/\n   ├─ index.cjs\n   └─ components/Button.cjs\n```\n\n- Both formats preserve the relative paths found under `src` by default (`preserveModulesRoot`).\n- Asset names are preserved (`[name][ext]`) so CSS, SVG, and other static files keep their filenames.\n- Declaration files mirror your source tree and ship alongside the build output, so `package.json#types` can target `dist/index.d.ts`.\n\n## Type declarations\n\n- Enabled by default through `unplugin-dts`.\n- Emits `.d.ts` files into the base `outDir` (`dist` unless overridden).\n- Automatically inserts or updates the `types` entry file (`dist/index.d.ts` by default).\n- Customize any `unplugin-dts` option (or disable emission entirely) with the `dts` option.\n\n## Recommended `package.json` exports\n\n```jsonc\n{\n    \"name\": \"my-component-lib\",\n    \"type\": \"module\",\n    \"main\": \"./dist/cjs/index.cjs\",\n    \"module\": \"./dist/esm/index.js\",\n    \"types\": \"./dist/index.d.ts\",\n    \"exports\": {\n        \".\": {\n            \"import\": \"./dist/esm/index.js\",\n            \"require\": \"./dist/cjs/index.cjs\",\n            \"types\": \"./dist/index.d.ts\",\n        },\n    },\n}\n```\n\n## Options\n\n| Option                | Type                                          | Default                     | Description                                                                                     |\n| --------------------- | --------------------------------------------- | --------------------------- | ----------------------------------------------------------------------------------------------- |\n| `entry`               | `string \\| string[] \\| Record\u003cstring,string\u003e` | `\"src/index.ts\"`            | Library entry passed to `build.lib.entry`.                                                      |\n| `outDir`              | `string`                                      | `\"dist\"`                    | Base output directory. Format folders (`esm`, `cjs`) are nested inside.                         |\n| `preserveModulesRoot` | `string`                                      | `\"src\"`                     | Root folder trimmed from emitted paths when `preserveModules` is on.                            |\n| `fileSuffix`          | `{ esm?: string; cjs?: string }`              | `{esm: \".js\", cjs: \".cjs\"}` | Customize per-format filename suffixes.                                                         |\n| `external`            | `(RegExp \\| string)[]`                        | bare imports                | Extra ids to mark as external.                                                                  |\n| `internal`            | `(RegExp \\| string)[]`                        | `[]`                        | Allow-listed bare ids that should stay bundled.                                                 |\n| `envNames`            | `{ esm?: string; cjs?: string }`              | `{esm: \"esm\", cjs: \"cjs\"}`  | Rename the environments if you need non-default names.                                          |\n| `formats`             | `(\"esm\" \\| \"cjs\")[]`                          | `[\"esm\", \"cjs\"]`            | Choose which formats to emit. Pass `[\"esm\"]` for ESM-only, etc.                                 |\n| `disableBuilder`      | `boolean`                                     | `false`                     | Skip registering the builder hook. Useful for CI workflows that call environments individually. |\n| `dts`                 | `boolean \\| PluginOptions`                    | `true`                      | Configure the bundled `unplugin-dts` instance or disable it.                                    |\n\n`PluginOptions` is the option type exported by `unplugin-dts`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmals%2Fvite-plugin-component-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkmals%2Fvite-plugin-component-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkmals%2Fvite-plugin-component-lib/lists"}