{"id":50551184,"url":"https://github.com/alfredosalzillo/modular-library","last_synced_at":"2026-06-04T03:30:22.041Z","repository":{"id":350668541,"uuid":"1207745121","full_name":"alfredosalzillo/modular-library","owner":"alfredosalzillo","description":"Modular library generator for Vite, Rollup, and Rolldown. Turn directories into tree-shakeable entry points.","archived":false,"fork":false,"pushed_at":"2026-05-23T12:17:02.000Z","size":94,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-23T14:12:39.797Z","etag":null,"topics":["developer-experience","developer-tools","modular-library","rolldown","rolldown-plugin","rollup","rollup-plugi","treeshakable","vite","vite-plugin"],"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/alfredosalzillo.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null},"funding":{"github":["alfredosalzillo"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2026-04-11T10:45:52.000Z","updated_at":"2026-05-23T12:17:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alfredosalzillo/modular-library","commit_stats":null,"previous_names":["alfredosalzillo/modular-library"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alfredosalzillo/modular-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredosalzillo%2Fmodular-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredosalzillo%2Fmodular-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredosalzillo%2Fmodular-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredosalzillo%2Fmodular-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alfredosalzillo","download_url":"https://codeload.github.com/alfredosalzillo/modular-library/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfredosalzillo%2Fmodular-library/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33888302,"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-04T02:00:06.755Z","response_time":64,"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":["developer-experience","developer-tools","modular-library","rolldown","rolldown-plugin","rollup","rollup-plugi","treeshakable","vite","vite-plugin"],"created_at":"2026-06-04T03:30:21.194Z","updated_at":"2026-06-04T03:30:22.029Z","avatar_url":"https://github.com/alfredosalzillo.png","language":"TypeScript","funding_links":["https://github.com/sponsors/alfredosalzillo"],"categories":[],"sub_categories":[],"readme":"# modular-library\n\n![npm version](https://img.shields.io/npm/v/modular-library)\n![node version](https://img.shields.io/badge/node-%3E%3D22-blue)\n![license](https://img.shields.io/github/license/alfredosalzillo/modular-library)\n\n`modular-library` is a utility library for generating modular libraries.\n\n## Why\n\nBuilding a modular library manually is usually tedious and error-prone:\n\n- keeping `package.json` `exports` in sync with your generated files,\n- wiring and maintaining complex glob-based inputs,\n- avoiding output path mistakes when your source tree grows.\n\n`modular-library` is a **zero-config** way to generate modular outputs for `vite`, `rollup`, and `rolldown` with predictable structure.\n\n## What is a modular library?\n\nA **modular library** is a library split into small, focused modules instead of one large, monolithic package.\n\nThis approach helps you:\n\n- keep each part of the library easier to understand and maintain,\n- reuse modules independently across projects,\n- reduce coupling between features,\n- improve scalability as the codebase grows,\n- be tree-shakeable so consumers only bundle what they import,\n- expose clear entry points for each public feature or component.\n\nTypical examples of modular libraries include:\n\n- UI libraries exposing per-component entries (for example `@acme/ui/button`, `@acme/ui/modal`),\n- utility libraries exposing per-domain modules (for example `@acme/utils/date`, `@acme/utils/string`),\n- SDKs exposing feature-based modules (for example `@acme/sdk/auth`, `@acme/sdk/storage`).\n\nWith `modular-library`, the goal is to make the creation of this kind of modular architecture faster and more consistent.\n\n### Why this is different from standard library mode\n\n| Approach | Example import | What happens |\n| --- | --- | --- |\n| Standard library mode | `import { button } from \"my-lib\";` | Requires evaluating the full package entry. |\n| Modular library (`modular-library`) | `import button from \"my-lib/button\";` | Loads only the `button` module code. |\n\n### Before vs. After output\n\n```text\n# Before (standard single-entry build)\ndist/\n  index.js\n\n# After (modular output with modular-library)\ndist/\n  button.js\n  modal.js\n  utils/\n    formatDate.js\n```\n\n## Installation\n\n\u003e **Node.js requirement:** This library supports only Node.js `22` or newer.\n\n```bash\nnpm install modular-library\n```\n\n## Usage\n\n`modular-library` provides dedicated plugins for `vite`, `rollup`, and `rolldown`.\n\n### Vite\n\n```ts\n// vite.config.ts\nimport { defineConfig } from \"vite\";\nimport modularLibrary from \"modular-library/vite\";\n\nexport default defineConfig({\n  plugins: [modularLibrary()],\n  build: {\n    lib: {\n      entry: [\"src/**/*.ts\"],\n      formats: [\"es\"],\n    },\n  },\n});\n```\n\n### Rollup\n\n```ts\n// rollup.config.ts\nimport modularLibrary from \"modular-library/rollup\";\n\nexport default {\n  input: [\"src/**/*.ts\"],\n  output: {\n    dir: \"dist\",\n    format: \"es\",\n  },\n  plugins: [modularLibrary()],\n};\n```\n\n### Rolldown\n\n```ts\n// rolldown.config.ts\nimport modularLibrary from \"modular-library/rolldown\";\n\nexport default {\n  input: [\"src/**/*.ts\"],\n  output: {\n    dir: \"dist\",\n    format: \"es\",\n  },\n  plugins: [modularLibrary()],\n};\n```\n\n### Options\n\nAll plugin variants support the same options:\n\n| Option | Type | Default | Description |\n| --- | --- | --- | --- |\n| `relative` | `string` | `\"src/\"` | Base path removed from generated output keys. |\n| `glob` | [`GlobOptions`](https://nodejs.org/api/fs.html#fsglobsyncpattern-options) | `undefined` | Options forwarded to `fs.globSync`. |\n| `transformOutputPath` | `(outputPath: string, inputPath: string) =\u003e string` | `undefined` | Customize each generated output path. |\n\nExample with options:\n\n```ts\nimport modularLibrary from \"modular-library/rollup\";\n\nexport default {\n  input: [\"src/**/*.ts\"],\n  output: {\n    dir: \"dist\",\n    format: \"es\",\n  },\n  plugins: [\n    modularLibrary({\n      relative: \"src/\",\n      transformOutputPath: (outputPath) =\u003e `modules/${outputPath}`,\n    }),\n  ],\n};\n```\n\n### Exports tip\n\nTo make your package consumable with subpath imports, add an `exports` map in your `package.json`:\n\n```json\n{\n  \"exports\": {\n    \"./*\": \"./dist/*.js\"\n  }\n}\n```\n\n## CLI\n\nYou can also use `modular-library` as a CLI with `npx`.\n\n### Check exports\n\nValidate that all `package.json` export targets exist and are inside your output directory:\n\n```bash\nnpx modular-library check\n```\n\nNamed options:\n\n- `--package-json` path to package manifest (default: `./package.json`)\n- `--out-dir` output directory to validate against (default: `./dist`)\n\nExample:\n\n```bash\nnpx modular-library check --package-json ./package.json --out-dir ./dist\n```\n\n## Development\n\n```bash\nnpm install\nnpm run build\nnpm test\n```\n\nTo test GitHub workflows locally, you can use [`act`](https://nektosact.com/).\n\n## License\n\nISC","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfredosalzillo%2Fmodular-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfredosalzillo%2Fmodular-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfredosalzillo%2Fmodular-library/lists"}