{"id":16844183,"url":"https://github.com/comandeer/rollup-lib-bundler","last_synced_at":"2025-08-22T10:45:23.190Z","repository":{"id":18832896,"uuid":"85403986","full_name":"Comandeer/rollup-lib-bundler","owner":"Comandeer","description":"Simple lib bundler","archived":false,"fork":false,"pushed_at":"2025-03-08T23:59:05.000Z","size":2999,"stargazers_count":15,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T08:31:34.658Z","etag":null,"topics":["babel","lib-bundler","rollup","terser"],"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/Comandeer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2017-03-18T13:41:08.000Z","updated_at":"2025-03-08T23:58:59.000Z","dependencies_parsed_at":"2024-06-19T01:55:11.492Z","dependency_job_id":"6ad59376-bbdb-43c4-b494-69099f8a2765","html_url":"https://github.com/Comandeer/rollup-lib-bundler","commit_stats":{"total_commits":717,"total_committers":5,"mean_commits":143.4,"dds":"0.14365411436541142","last_synced_commit":"7b048b1aca158cc2dffb05251bfa3d6b64bbd1ba"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comandeer%2Frollup-lib-bundler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comandeer%2Frollup-lib-bundler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comandeer%2Frollup-lib-bundler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comandeer%2Frollup-lib-bundler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Comandeer","download_url":"https://codeload.github.com/Comandeer/rollup-lib-bundler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243981103,"owners_count":20378517,"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":["babel","lib-bundler","rollup","terser"],"created_at":"2024-10-13T12:54:52.752Z","updated_at":"2025-03-17T05:31:59.331Z","avatar_url":"https://github.com/Comandeer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @comandeer/rollup-lib-bundler\n\n[![Build Status](https://github.com/Comandeer/rollup-lib-bundler/workflows/CI/badge.svg)](https://github.com/Comandeer/rollup-lib-bundler/actions) [![codecov](https://codecov.io/gh/Comandeer/rollup-lib-bundler/branch/main/graph/badge.svg)](https://codecov.io/gh/Comandeer/rollup-lib-bundler) [![npm (scoped)](https://img.shields.io/npm/v/@comandeer/rollup-lib-bundler.svg)](https://npmjs.com/package/@comandeer/rollup-lib-bundler)\n\nSuper opinionated library bundler using [Rollup](https://github.com/rollup/rollup), [Babel](https://github.com/babel/babel) and [terser](https://github.com/terser/terser).\n\n## Installation\n\n```bash\nnpm install @comandeer/rollup-lib-bundler --save-dev\n```\n\n## Usage\n\nJust make it a npm script:\n\n```json\n\"scripts\": {\n\t\"build\": \"rlb\"\n}\n```\n\n## Configuration\n\nNo configuration. Consider it a feature.\n\n## How does it work?\n\nIt gets `package.json` from the current working directory, parses it and fetches the neeeded info:\n\n* `name`, `author`, `version` and `license` to create beautiful banner comment,\n* `exports.import` to determine where to save ESM bundle (see the [\"Supported `exports` syntax\"](#supported-exports-syntax) section for more info).\n\nThen the bundling happens. The default entry point for Rollup is `src/index.js`.\n\n\u003e [!WARNING]\n\u003e Please note that **dist directory is purged before bundling**! So if anything should be there alongside the bundle, it should be added there _after_ the bundling.\n\n### Assumed file structure\n\nThis is very opinionated bundler and it assumes that the project's file structure looks like the one below:\n\n```\npackage/\n|- package.json\n|- src/\n|     |- index.js\n|     |- some-other-chunk.js\n|- dist/\n|      |- bundled-index.mjs\n|      |- bundled-index.mjs.map\n|      |- bundled-some-other-chunk.mjs\n|      |- bundled-some-other-chunk.mjs.map\n```\n\n* `package.json` is in the root of the package (the only bit we all agree on!),\n* `src/` directory contains package's source,\n\t* `index.js` is the main entrypoint of the package,\n\t* `some-other-chunk.js` is the optional additional entrypoint (see [#mutliple-bundles](Multiple bundles) section for more info),\n* `dist/` directory contains bundled code.\n\nBundler search for source files with the following extensions in the following order:\n\n* `.mts`,\n* `.ts`,\n* `.mjs`,\n* `.js`,\n* `.cts`,\n* `.cjs`.\n\n## Multiple bundles\n\nBy default, `src/index.js` is treated as the only entry point. However, using [subpath exports](https://nodejs.org/api/packages.html#subpath-exports) you can create several bundled chunks/files. Example:\n\n```json\n\"exports\": {\n\t\".\": {\n\t\t\"import\": \"./dist/package.mjs\"\n\t},\n\n\t\"./chunk\": {\n\t\t\"import\": \"./dist/chunk.mjs\"\n\t}\n}\n```\n\nIn this case two source files will be bundled:\n* `src/index.js`:\n\t* ESM output: `dist/package.mjs`,\n* `src/chunk.js`:\n\t* ESM output: `dist/chunk.mjs`.\n\nEach subpath is translated to appropriate file in `src` directory. Basically, `./` at the beginning is translated to `src/` and the name of the subpath is translated to `\u003csubpath\u003e.\u003cextension\u003e` (e.g. `./chunk` → `src/chunk.js`). The only exception is the `.` subpath, which is translated to `src/index.js`.\n\nAs of version 0.19.0 the bundler also automatically omits bundling bundles inside other bundles. If there were an import of the `src/chunk.js` file inside the `src/index.js` file in the above structure, then the `dist/package.(c|m)js` file would contain an import from `dist/chunk.(c|m)js` file instead of the content of the other bundle.\n\n## Supported `exports` syntax\n\nThe bundler supports only the subset of the `exports` syntax allowed by the Node.js:\n\n* **`exports` as a string**:\n\n\t```json\n\t{\n\t\t\"exports\": \"./dist/package.mjs\"\n\t}\n\t```\n* **subpaths as strings**:\n\n\t```json\n\t{\n\t\t\"exports\": {\n\t\t\t\".\": \"./dist/package.mjs\",\n\t\t\t\"./subpath\": \"./dist/chunk.js\"\n\t\t}\n\t}\n\t```\n* **`exports` with conditional exports**:\n\n\t```json\n\t{\n\t\t\"exports\": {\n\t\t\t\"types\": \"./dist/package.d.mts\",\n\t\t\t\"import\": \"./dist/package.mjs\"\n\t\t}\n\t}\n\t```\n* **subpaths with conditional exports**:\n\n\t```json\n\t{\n\t\t\"exports\": {\n\t\t\t\".\": {\n\t\t\t\t\"types\": \"./dist/package.d.mts\",\n\t\t\t\t\"import\": \"./dist/package.mjs\"\n\t\t\t}\n\t\t}\n\t}\n\t```\n## Transpilation\n\nThe bundler transpiles all the code with Babel. The transpilation target can be specified with the `engines.node` field in the `package.json` file:\n\n```json\n{\n\t\"engines\": {\n\t\t\"node\": \"20.1.0\"\n\t}\n}\n```\n\nAny valid [semver syntax](https://semver.npmjs.com/) is supported.\n\nIf the `engines.node` field is not specified or it contains invalid version, the bundler fallbacks to the `current` version – so the version of Node that was used to run the bundler.\n\n## TypeScript support\n\nStarting from v0.17.0 the bundler is able also to bundle TypeScript projects. There is no configuration needed, just replace the `.js` extension with the `.ts` one! Also ensure that there's a valid `tsconfig.json` file in the root of your project. If you want to provide different configuration for the bundler, place a `tsconfig.rlb.json` file instead.\n\n\u003e [!WARNING]\n\u003e The [`outDir` config option](https://www.typescriptlang.org/tsconfig/#outDir) is overridden by the bundler to point to the same directory as the one in the Rollup's configuration.\n\u003e See [#327](https://github.com/Comandeer/rollup-lib-bundler/issues/327) for more details.\n\nThe bundler also bundles `.d.ts` files but only if you specified the `exports.types` field in your `package.json`.\n\nSample configuration for a TS project:\n\n```json\n\"exports\": {\n\t\".\": {\n\t\t\"types\": \"./dist/index.d.ts\",\n\t\t\"import\": \"./dist/index.mjs\"\n\t},\n\n\t\"./chunk\": {\n\t\t\"import\": \"./dist/chunk.mjs\"\n\t}\n}\n```\n\nIn this case two source files will be bundled:\n* `src/index.ts`:\n\t* ESM output: `dist/index.mjs`,\n\t* DTS output: `dist/index.d.ts`,\n* `src/chunk.ts`:\n\t* ESM output: `dist/chunk.mjs`,\n\t* DTS output: none (there's no `types` field).\n\n## Bundling executables (aka binaries)\n\nFrom v0.19.0 `rlb` can also bundle executables defined in the [`bin` field](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin) of the `package.json`. It supports both the simple format of that field and the complex one. Source files for binaries must be placed in the `src/__bin__` directory with the same name as in the `bin` field. All source file formats supported for `exports` bundles are also supported for the `bin` ones.\n\nAll bundles created from the `bin` field are saved in the ESM format. The bundler will also preserve shebang in the produced bundle.\n\n### Example with the simple `bin` format\n\n```json\n{\n\t\"name\": \"some-package\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"import\": \"./dist/index.mjs\"\n\t\t}\n\t},\n\t\"bin\": \"./dist/bin.mjs\"\n}\n```\n\nIn that case bundler excepts the following source file structure:\n\n```\nsome-package/\n|- package.json\n|- src/\n|     |- index.js\n|     |- __bin__/\n|     |         |- some-package.js\n```\n\nPlease note that when using the simple `bin` format (so just the path to the executable, without its name), the bundler will look for the source file with the name of the package (derived from the `name` field in the `package.json` files).\n\n### Example with the complex `bin` format\n\n```json\n{\n\t\"name\": \"some-package\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"import\": \"./dist/index.mjs\"\n\t\t}\n\t},\n\t\"bin\": {\n\t\t\"whatever\": \"./dist/bin.mjs\",\n\t\t\"another-one\": \"./dist/bin2.js\"\n\t}\n}\n```\n\nIn that case bundler excepts the following source file structure:\n\n```\nsome-package/\n|- package.json\n|- src/\n|     |- index.js\n|     |- __bin__/\n|     |         |- whatever.js\n|     |         |- another-one.js\n```\n\n## Support for non-standard dist directories\n\nFrom v0.20.0 the bundler officially supports non-standard dist directories (different than the `./dist` one). The dist directory is resolved from the `exports` field in the `package.json`, e.g.:\n\n```json\n\"exports\": {\n\t\".\": {\n\t\t\"import\": \"./hublabubla/package.mjs\"\n\t}\n}\n```\n\nIn the above example, the `./hublabubla` directory will be used instead of the `./dist` one.\n\nThe bundler supports also multiple non-standard dist directories, e.g.:\n\n```json\n\"exports\": {\n\t\".\": {\n\t\t\"import\": \"./bublahubla/package.mjs\"\n\t},\n\t\"./chunk\": \"./hublabubla/chunk.mjs\"\n}\n```\n\n\u003e [!WARNING]\n\u003e Non-standard dist directories are purged befored the bundling!\n\u003e So if anything should be there alongside the bundle, it should be added there _after_ the bundling.\n\n## Configuring VSC to correctly suggest imports\n\nVSC uses TypeScript rules to suggest imports. However, TS uses CJS rules by default, ignoring the constraints of the `exports` field and suggesting the whole file paths (e.g. `\u003cpackage\u003e/dist/\u003cfile\u003e` instead of `\u003cpackage\u003e/\u003csubmodule-name\u003e`). To fix it, TS must be configured by `tsconfig.json` or `jsconfig.json` file to [resolve modules according to ESM rules](https://www.typescriptlang.org/tsconfig#moduleResolution):\n\n```json5\n{\n\t\"module\": \"node16\",\n\t// or\n\t\"moduleResolution\": \"node16\"\n}\n```\n\n## License\n\nSee [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomandeer%2Frollup-lib-bundler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomandeer%2Frollup-lib-bundler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomandeer%2Frollup-lib-bundler/lists"}