{"id":13660748,"url":"https://github.com/manferlo81/bundlib","last_synced_at":"2025-04-04T04:20:11.934Z","repository":{"id":34635229,"uuid":"180996230","full_name":"manferlo81/bundlib","owner":"manferlo81","description":"An automatic library bundler powered by Rollup.js.","archived":false,"fork":false,"pushed_at":"2025-04-01T01:01:54.000Z","size":5287,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T09:05:49.043Z","etag":null,"topics":["bundle","bundler","library","rollup","typescript"],"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/manferlo81.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-04-12T11:40:24.000Z","updated_at":"2025-03-13T02:31:50.000Z","dependencies_parsed_at":"2024-06-27T21:59:32.961Z","dependency_job_id":"a924651c-3973-40ca-9927-63577a55e7fb","html_url":"https://github.com/manferlo81/bundlib","commit_stats":{"total_commits":1924,"total_committers":5,"mean_commits":384.8,"dds":0.4584199584199584,"last_synced_commit":"4f469e63413ef475a7575d5c6ff9d3bd614f697d"},"previous_names":[],"tags_count":86,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manferlo81%2Fbundlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manferlo81%2Fbundlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manferlo81%2Fbundlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manferlo81%2Fbundlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manferlo81","download_url":"https://codeload.github.com/manferlo81/bundlib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247118646,"owners_count":20886591,"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":["bundle","bundler","library","rollup","typescript"],"created_at":"2024-08-02T05:01:25.315Z","updated_at":"2025-04-04T04:20:11.925Z","avatar_url":"https://github.com/manferlo81.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Bundlib\n\n[![CircleCI](https://circleci.com/gh/manferlo81/bundlib.svg?style=svg)](https://circleci.com/gh/manferlo81/bundlib)\n[![CI](https://github.com/manferlo81/bundlib/actions/workflows/ci.yml/badge.svg?branch=main\u0026event=push)](https://github.com/manferlo81/bundlib/actions/workflows/ci.yml)\n[![npm](https://badgen.net/npm/v/bundlib)](https://www.npmjs.com/package/bundlib)\n[![codecov](https://codecov.io/gh/manferlo81/bundlib/branch/main/graph/badge.svg?token=PrVW2D6bfl)](https://codecov.io/gh/manferlo81/bundlib)\n[![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/bundlib)](https://libraries.io/npm/bundlib)\n[![install size](https://packagephobia.com/badge?p=bundlib)](https://packagephobia.com/result?p=bundlib)\n[![types](https://img.shields.io/npm/types/bundlib.svg)](https://github.com/microsoft/typescript)\n[![Known Vulnerabilities](https://snyk.io/test/github/manferlo81/bundlib/main/badge.svg)](https://snyk.io/test/github/manferlo81/bundlib)\n[![license](https://badgen.net/github/license/manferlo81/bundlib)](LICENSE)\n\nAn automatic library bundler powered by [Rollup.js](https://github.com/rollup/rollup).\n\n\u003e :warning: **Bundlib** is under development, please [file a new issue](https://github.com/manferlo81/bundlib/issues) if you find any issue or bug, suggestions are welcome as well.\n\n## In this guide\n\n* [Install](#install)\n* [Build](#build)\n* [Configuration](#configuration)\n  * [Automatic Configuration](#automatic-configuration)\n  * [Advanced Configuration](#advanced-configuration)\n* [Options](#options)\n  * [`input`](#option-input)\n  * [`sourcemap`](#option-sourcemap)\n  * [`esModule`](#option-esmodule)\n  * [`interop`](#option-interop)\n  * [`chunks`](#option-chunks)\n  * [`format`](#option-format)\n  * [`name`](#option-name)\n  * [`id`](#option-id)\n  * [`extend`](#option-extend)\n  * [`globals`](#option-globals)\n  * [`min`](#option-min)\n  * [`equals`](#option-equals)\n  * [`cache`](#option-cache)\n  * [`project`](#option-project)\n  * [`skip`](#option-skip)\n* [Selective Options](#selective-options)\n  * [Value based selective format](#value-based-selective-format)\n    * [As value](#as-value)\n    * [As nullish](#as-nullish)\n    * [As function returning valid value or nullish](#as-function-returning-valid-value-or-nullish)\n    * [As object](#as-object)\n      * [The special `default` property](#the-special-default-property)\n      * [The special `api` property](#the-special-api-property)\n  * [Boolean based selective format](#boolean-based-selective-format)\n    * [As boolean](#as-boolean)\n    * [As key](#as-key)\n    * [As array of keys](#as-array-of-keys)\n    * [The special `api` key](#the-special-api-key)\n    * [As value based](#as-value-based)\n* [Using the CLI tool](#using-the-cli-tool)\n* [Using **Bundlib** programmatically](#using-bundlib-programmatically)\n  * [Functions](#functions)\n    * [function `bundlib`](#function-bundlib)\n    * [function `readPkg`](#function-readpkg)\n    * [function `analyzePkg`](#function-analyzepkg)\n    * [function `pkgToConfigs`](#function-pkgtoconfigs)\n    * [function `configsFromPkg`](#function-configsfrompkg)\n  * [Types](#types)\n    * [type `BundlibConfig`](#type-bundlibconfig)\n    * [type `PkgAnalyzed`](#type-pkganalyzed)\n    * [type `ModuleBuildOptions`](#type-modulebuildoptions)\n    * [type `BrowserBuildOptions`](#type-browserbuildoptions)\n    * [type `TypesBuildOptions`](#type-typesbuildoptions)\n    * [type `BundlibAPIOptions`](#type-bundlibapioptions)\n  * [Selective Types](#selective-types)\n    * [type `SelectiveValueBasedOption`](#type-selectivevaluebasedoption)\n    * [type `SelectiveBoolBasedOption`](#type-selectiveboolbasedoption)\n    * [type `BuildType`](#type-buildtype)\n    * [type `SelectiveStringOption`](#type-selectivestringoption)\n    * [type `SelectiveSourcemapOption`](#type-selectivesourcemapoption)\n    * [type `SelectiveEsModuleOption`](#type-selectiveesmoduleoption)\n    * [type `SelectiveInteropOption`](#type-selectiveinteropoption)\n    * [type `SelectiveMinOption`](#type-selectiveminoption)\n    * [type `SelectiveSkipOption`](#type-selectiveskipoption)\n* [Plugin Notes](#plugin-notes)\n  * [`@rollup/plugin-eslint`](#plugin-rollupplugin-eslint)\n  * [`rollup-plugin-typescript2`](#plugin-rollup-plugin-typescript2)\n* [Features](#features)\n\n## Install\n\n```bash\nnpm install bundlib --save-dev # or for short: npm i bundlib -D\n```\n\n## Build\n\n**Bundlib** will try to find your entry point file in the **`src`** folder. You can manually set your entry points using the [`input`](#option-input) option.\n\n### CommonJS module\n\nTo build a `CommonJS Module` simply add a `\"main\"` field to your `package.json` pointing to the output file, [see the configuration section](#configuration) for extra options.\n\n### ES module\n\nTo build a `ES Module` add a `\"module\"` field to your `package.json` pointing to the output file, [see the configuration section](#configuration) for extra options.\n\n### IIFE, AMD and UMD build\n\nFor `IIFE`, `AMD` or `UMD` builds, add a `\"browser\"` field to your `package.json`. The default format is `\"umd\"` but it can be changed to `\"iife\"` or `\"amd\"` using the [`format`](#option-format) option, see the [configuration section](#configuration) for more info and extra options.\n\n## Configuration\n\n### Automatic Configuration\n\n**Bundlib** will configure [**Rollup**](https://github.com/rollup/rollup) according to you `package.json` data, see [Advanced Configuration](#advanced-configuration) for more information.\n\n#### `\"main\"`\n\nThe `\"main\"` field will be used as your **CommonJS module** output, if not present, **CommonJS Module** build will be skipped. You can skip the build manually using the [`skip`](#option-skip) option.\n\n#### `\"module\"` or `\"jsnext:main\"`\n\nThe `\"module\"` field will be used as your **ES Module** output, if not present, **ES Module** build will be skipped. You can skip the build manually using the [`skip`](#option-skip) option. `\"jsnext:main\"` field will also be honored if `\"module\"` field is not present, but it is recommended to use the `\"module\"` field.\n\n#### `\"browser\"`\n\nThe `\"browser\"` field will be used as your **Browser** build output, if not present, **Browser** build will be skipped. You can skip the build manually using the [`skip`](#option-skip) option. **Bundlib** only supports `string` type `\"browser\"` field, it will **throw** otherwise.\n\n#### `\"bin\"`\n\nThe `\"bin\"` field will be used as your **Binary** build output, if not present, **Binary** build will be skipped. You can skip the build manually using the [`skip`](#option-skip) option. **Bundlib** only supports `string` type `\"bin\"` field, it will **throw** otherwise.\n\n#### `\"types\"` or `\"typings\"`\n\nThe `\"types\"` field will be used as your **Types** output if you are using `typescript`. You can skip types generation using the [`skip`](#option-skip) option. `\"typings\"` field will also be honored if `\"types\"` field is not present.\n\n#### `\"dependencies\"`\n\nThe `\"dependencies\"` field will be used to detect installed packages, it will also be used to set external dependencies for your **CommonJS module**, **ES module**, and **Binary** builds, for **Browser** build dependencies will be bundled into the output file unless otherwise specified using the [`globals`](#option-globals) option.\n\n#### `\"devDependencies\"`\n\nThe `\"devDependencies\"` field will be used to detect installed packages.\n\n#### `\"peerDependencies\"`\n\nThe `\"peerDependencies\"` field will be used as external dependencies for your **CommonJS module,**, **ES module**, and **Binary** builds.\n\n#### `\"bundlib\"`\n\nThe `\"bundlib\"` field can be used for advanced configuration, see [Advanced Configuration](#advanced-configuration) for more information.\n\n### Advanced Configuration\n\nAdvanced configuration can be done using the `\"bundlib\"` field in your `package.json` or by using one of the supported [configuration files](#configuration-files).\n\n#### Configuration in `package.json`\n\nSet `\"bundlib\"` field in your `package.json` to an `object` with your configuration. See [options](#options) for more information.\n\n***example***\n\n```json\n// package.json\n{\n  \"name\": \"my-lib\",\n  \"version\": \"1.0.0\",\n  \"browser\" : \"dist/my-lib.amd.js\",\n  \"bundlib\": {\n    \"format\": \"amd\"\n  }\n  ...\n}\n```\n\nYou can also set `\"bundlib\"` field in `package.json` to a `string` as a path, relative to the project root, pointing to a `.json`, `.yaml`, `.yml`, `.js`, `.cjs`, `.mjs` or `.ts`, or `json` or `yaml` format file without extension containing the configuration.\n\n***example***\n\n```json\n// package.json\n{\n  \"name\": \"my-lib\",\n  \"version\": \"1.0.0\",\n  \"browser\" : \"dist/my-lib.amd.js\",\n  \"bundlib\": \"options.yml\"\n  // ...\n}\n```\n\nthen...\n\n```yaml\n# options.yaml\nformat: amd\n```\n\n#### Configuration files\n\nIf `\"bundlib\"` field not present in your `package.json`, **Bundlib** will try to find your configuration file using the following order...\n\n* .bundlibrc (json or yaml format)\n* .bundlibrc.json\n* .bundlibrc.yaml\n* .bundlibrc.yml\n* .bundlibrc.js\n* bundlib.config.js\n* bundlib.config.cjs\n* bundlib.config.mjs\n* bundlib.config.ts\n\nSee the [list of options](#options) below.\n\n## Options\n\nThe option object may contain any of the following properties. Any invalid or unknown option will cause **Bundlib** to **throw** at build time. Any option or sub-option set to `null` will be ignored.\n\n### option `input`\n\nThe path to the files to be used as entry points for each of your builds. This option supports [`value based selective format`](#value-based-selective-format).\n\n```typescript\ninput: SelectiveStringOption;\n```\n\nSee [`SelectiveStringOption`](#type-selectivestringoption).\n\n### option `sourcemap`\n\nWhether or not to generate source maps. Valid values are `boolean`, `\"inline\"` and `\"hidden\"`. The default value is `true` if you don't provide this option. See [Rollup documentation](https://rollupjs.org/guide/en/#outputsourcemap) for more information.\n\nThis option supports [value based](#value-based-selective-format) and [boolean based](#boolean-based-selective-format) selective format.\n\n```typescript\nsourcemap: SelectiveSourcemapOption;\n\ndefault true;\n```\n\nSee [`SelectiveSourcemapOption`](#type-selectivesourcemapoption).\n\n### option `esModule`\n\nWhether or not to add a `__esModule: true` property to your module. Valid values are `boolean` and `\"if-default-prop\"`. The default value is `false` if you don't provide this option.\n\nThis option supports [value based](#value-based-selective-format) and [boolean based](#boolean-based-selective-format) selective format.\n\n```typescript\nesModule: SelectiveEsModuleOption;\n\ndefault false;\n```\n\nSee [`SelectiveEsModuleOption`](#type-selectiveesmoduleoption).\n\n### option `interop`\n\nWhether or not to add an interop block. Valid values are `boolean`, `\"default\"`, `\"esModule\"`, `\"compat\"`, `\"auto\"` and `\"defaultOnly\"`. Rollup doesn't support `interop` option as a `boolean` anymore, we still support it by turning `true` into `\"compat\"` and `false` into `\"default\"` before we pass it to Rollup. The default value is `\"default\"` if you don't provide this option.\n\nThis option supports [value based](#value-based-selective-format) and [boolean based](#boolean-based-selective-format) selective format.\n\n```typescript\ninterop: SelectiveInteropOption;\n\ndefault \"default\";\n```\n\nSee [`SelectiveInteropOption`](#type-selectiveinteropoption).\n\n### option `chunks`\n\nA map of chunks to be built as `CommonJS` modules. The object `key` represents the input file and the `value` represents the output file, relative to the project root. Files created using this option won't be bundled into the `CommonJS` and `Binary` builds and will be imported (required) instead.\n\n```typescript\nchunks: Record\u003cstring, string\u003e;\n```\n\n### option `format`\n\nDefines the format to be used for the `Browser` build.\n\n```typescript\nformat: 'iife' | 'amd' | 'umd';\n\ndefault 'umd';\n```\n\n### option `name`\n\nThe name to be used to expose your library to the global scope in a `IIFE` or `UMD` browser build. If not provided it will default to the camelcased, unscoped `\"name\"` field in `package.json` or the camelcased directory name. If none of those can be obtained, it will **throw** at build time.\n\n```typescript\nname: string;\n```\n\n### option `id`\n\n```typescript\nid: string;\n```\n\nOptional amd id for `AMD` or `UMD` build.\n\nIf not present, `AMD` `define` method will use no id.\n\n### option `extend`\n\nWhether or not to extend the globally exposed [name](#option-name) on a `IIFE` or `UMD` build.\n\n```typescript\nextend: boolean;\n\ndefault false;\n```\n\n### option `globals`\n\n`Object` or `array` to map names to globals in `Browser` build.\n\n```typescript\nglobals: { [name: string]: string } | string[];\n\ndefault {};\n```\n\n### option `min`\n\nDefines which files should be used to build an additional minified version, if `true` will affect all modules. The minified file will be renamed from `*.ext` to `*.min.ext`. This option will override the default behavior of the [`--dev`, `-d` *cli option*](#--dev--d) , which means only the minified version will be actually minified, the normal version will **NOT** be minified even if you don't set the [`--dev`, `-d` cli option](#--dev--d). This option supports  [boolean based selective format](#boolean-based-selective-format).\n\n```typescript\nmin: SelectiveMinOption;\n\ndefault false;\n```\n\nSee [`SelectiveMinOption`](#type-selectiveminoption).\n\n### option `equals`\n\nTransforms type export for CommonJS module using `export = ...` instead of `export default ...`.\n\n\u003e :warning: *Note that this option should only be used when your library has a* `default` *export and no* `named` *exports, otherwise it may cause the type declarations to become invalid.*\n\n```typescript\nequals: boolean;\n\ndefault false;\n```\n\n### option `cache`\n\nDefines the directory to be used for cache, relative to the project root.\n\n```typescript\ncache: string;\n\ndefault \"node_modules/.cache/bundlib\";\n```\n\n### option `project`\n\nDefines the location of typescript `tsconfig.json` file, relative to the project root. This option supports [value based selective format](#value-based-selective-format).\n\n```typescript\nproject: SelectiveStringOption;\n\ndefault \"tsconfig.json\"\n```\n\nSee [`SelectiveStringOption`](#type-selectivestringoption).\n\n### option `skip`\n\nDefined which build **Bundlib** should skip. This option supports [boolean based selective format](#boolean-based-selective-format).\n\n```typescript\nmin: SelectiveSkipOption;\n\ndefault false;\n```\n\nSee [`SelectiveSkipOption`](#type-selectiveskipoption).\n\n## Selective Options\n\nSome options support a `selective` format to allow for a more flexible configuration.\n\nSee [Selective Types](#selective-types) section for more information.\n\nNote that some options support different selective formats. `Boolean` type options support `boolean` based format which is an extension of `value` based format, while others support only `value` based format.\n\nSee [`input` option](#option-input), [`sourcemap` option](#option-sourcemap), [`esModule` option](#option-esmodule), [`interop` option](#option-interop), [`min` option](#option-min) and [`project` option](#option-project).\n\n### Value based selective format\n\nThe `value` based selective format allows you to enter a `value` or an `object` to set independent values.\n\n#### As value\n\n```typescript\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = 'some-string';\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = 'some-other-string';\n```\n\n#### As nullish\n\n```typescript\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = null;\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = undefined;\n```\n\n#### As function returning valid value or nullish\n\n```typescript\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = () =\u003e 'some-string';\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = (key) =\u003e {\n  return key === 'module' ? 'module-value' : 'other-value';\n};\n```\n\n#### As object\n\n```typescript\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = { main: 'main-value' };\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = { module: 'module-value' };\n```\n\n#### The special `default` property\n\nYou can override the default value as well using the `default` object key.\n\n```typescript\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = {\n  default: 'default',\n  main: 'string',\n};\n\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = {\n  default: 'default',\n  module: 'module',\n};\n```\n\n#### The special `api` property\n\nThe `api` object key represents `main`, `module` and `browser`.\n\n```typescript\nconst value: SelectiveValueBasedOption\u003cBuildType, string\u003e = {\n  api: 'string',\n};\n```\n\n### Boolean based selective format\n\nThe `boolean` based selective format is an extension of the a `value` based selective format, except `boolean` can be used as a value as well, and it allows `keys` in the `positive` or `negative` format in addition to what `value` based selective format normally accepts.\n\n#### As boolean\n\nYou can set it to a `boolean` value.\n\n```typescript\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = true;\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = false;\n```\n\n#### As key\n\nYou can set it to any of the valid keys, in the `positive` format (ex: `main` or `+main`) or `negative` format (ex: `!main` or `-main`). Valid keys are usually: `main`, `module`, `browser` and `bin` except for [`SelectiveSkipOption`](#type-selectiveskipoption) which also accepts `types` as key. It will also accepts [the special `api` key](#the-special-api-key).\n\n```typescript\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = 'main';\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = 'api';\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = '!api';\n```\n\n#### As array of keys\n\nAny key that can be used as as [`single key`](#as-key), can be as well used in an array. The first key sets the default state for the result, and the additional keys extend that initial state.\n\n```typescript\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = ['main', 'module'];\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = ['!browser', '!main'];\n```\n\n#### The special `api` key\n\nThe `api` special keys sets (or removes) `main`, `module` and `browser` at the same time.\n\n```typescript\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = 'api';\nconst value: SelectiveBoolBasedOption\u003cBuildType, never\u003e = ['api', '!browser'];\n```\n\n#### As value based\n\nThe `boolean` based selective format is an extension of the `value` based one. It accepts values as `boolean` and objects containing `boolean` values, in addition to what a `value` based selective format normally accepts.\n\n```typescript\nconst value: SelectiveBoolBasedOption\u003cBuildType, 'text'\u003e = true;\nconst value: SelectiveBoolBasedOption\u003cBuildType, 'text'\u003e = { default: false, main: 'text' };\n```\n\n## Using the CLI tool\n\n```bash\nbundlib [options] [command]\n```\n\n### CLI Options\n\nCombine options according to your needs. Run `bundlib --help` or `bundlib -h` for a detailed help.\n\n#### `--dev`, `-d`\n\nCreate development, not minified builds. Builds affected by the [`min`](#option-min) option will ignore this option.\n\n#### `--silent`, `-s`\n\nPrevent messages from showing in the console.\n\n#### `--version`, `-v`\n\nShow **Bundlib** version.\n\n#### `--help`, `-h`\n\nShow detailed help about the CLI tool.\n\n### CLI Commands\n\n#### `build`\n\nBuild your library for production\n\n#### `watch`\n\nRuns Bundlib in watch mode\n\n## Using Bundlib programmatically\n\nBundlib exposes some `function` and `types` you can `import`\n\n***example***\n\n```javascript\n// rollup.config.js\n\nimport { configsFromPkg } from 'bundlib';\n\nconst dev = !process.env.production;\n\nexport default configsFromPkg(\n  process.cwd(),\n  { dev },\n);\n```\n\n## Functions\n\n### function `bundlib`\n\nAn All-in-one function combining `readPkg`, `analyzePkg` and `pkgToConfigs`. Just pass the directory where `package.json` is located, and it will return an array of Rollup configuration objects.\n\n* *Syntax*\n\n```typescript\nasync function bundlib(\n  cwd: string,\n  options?: BundlibAPIOptions | null | undefined,\n): Promise\u003cArray\u003crollup.RollupOptions\u003e\u003e;\n```\n\n* `arguments`\n  * `cwd`: A string representing the path where `package.json` is located.\n  * `options`: Some options to be passed to [`pkgToConfigs`](#function-pkgtoconfigs) function.\n* `return`: An array of Rollup configs.\n\n### function `readPkg`\n\nReads the content of `package.json` and returns it. It will throw a `TypeError` if `package.json` content is not an `object`.\n\n* *Syntax*\n\n```typescript\nasync function readPkg(cwd: string): Promise\u003cPkgJson\u003e;\n```\n\n* `arguments`\n  * `cwd`: A string representing the path where `package.json` is located.\n* `return`: A `Promise` which resolves to `package.json` content.\n\n### function `analyzePkg`\n\nAnalyzes `package.json` content, resolve bundlib `configuration` and it turns it into more useful information about the build.\n\n* *Syntax*\n\n```typescript\nasync function analyzePkg(\n  cwd: string,\n  pkg: PkgJson,\n): Promise\u003cPkgAnalyzed\u003e;\n```\n\n* `arguments`\n  * `cwd`: A string representing the path where configuration file should be located.\n  * `pkg`: The content of `package.json`.\n* `return`: A `Promise` which resolves to information and tools, useful to configure rollup.\n\n\u003e If `pkg` not provided it will read `package.json` from the current working directory `cwd`. But this behavior will be removed in the future. So, to avoid problems in the future, please pass `pkg`\n\nSee [`PkgAnalyzed`](#type-pkganalyzed).\n\n### function `pkgToConfigs`\n\nTakes a [`PkgAnalyzed`](#type-pkganalyzed) object an turns it into an array of config objects, ready to be used by Rollup.\n\n* *Syntax*\n\n```typescript\nfunction pkgToConfigs(\n  analyzed: PkgAnalyzed,\n  options?: BundlibAPIOptions | null | undefined,\n): Array\u003crollup.RollupOptions\u003e;\n```\n\n* `arguments`\n  * `analyzed`: The [`PkgAnalyzed`](#type-pkganalyzed) returned by [`analyzePkg`](#function-analyzepkg) function.\n  * `options`: Some options which define some configurations.\n* `return`: An array of Rollup configs.\n\nSee [`PkgAnalyzed`](#type-pkganalyzed) and [`BundlibAPIOptions`](#type-bundlibapioptions).\n\n### function `configsFromPkg`\n\nCreates an array of rollup config object, based on the content of `package.json` and bundlib configuration file. It is a combination of [`readPkg`](#function-readpkg), [`analyzePkg`](#function-analyzepkg) and [`pkgToConfigs`](#function-pkgtoconfigs) functions. It is exported as a way to \"do it all in one step\", but you can use the independent functions to have a bit mor control over the process.\n\n```typescript\nasync function configsFromPkg(\n  cwd: string,\n  options?: BundlibAPIOptions | null | undefined,\n  pkg: PkgJson = read(cwd + '/package.json'),\n): Promise\u003cArray\u003crollup.RollupOptions\u003e\u003e;\n```\n\n* `arguments`\n  * `cwd`: A string representing the path where `package.json` and configuration file should be located.\n  * `options`: An object with options to create the configs.\n  * `pkg`: The content of `package.json`.\n* `return`: A `Promise` which resolves to information and tools, useful to configure rollup.\n\nIf `pkg` not provided it will be read from the current working directory `cwd`.\n\n### function config\n\nA function that returns it's only argument. It helps to have code completion and type check when using javascript config file.  See example.\n\n```typescript\nfunction config(config: BundlibConfig): BundlibConfig;\n```\n\n* *Example*\n\nFirst the \"normal\" way...\n\n```javascript\n// bundlib.config.js\n\nexport default {\n  input: 'src/index.js',\n  interop: true,\n  // ... the rest of your config here\n};\n```\n\n... You can improve your experience by using this helper function... when using vscode, for example, it will type check and autocomplete your config file while you type.\n\n```javascript\nimport { config } from 'bundlib';\n\nexport default config({\n  input: 'src/index.js',\n  interop: true,\n  // ... the rest of your config here\n});\n```\n\n## Types\n\nThis are som of the types exported but bundlib.\n\n### type `BundlibConfig`\n\n```typescript\ninterface BundlibConfig {\n  readonly input?: SelectiveStringOption;\n  readonly sourcemap?: SelectiveSourcemapOption;\n  readonly esModule?: SelectiveEsModuleOption;\n  readonly interop?: SelectiveInteropOption;\n  readonly cache?: string | null;\n  readonly chunks?: Record\u003cstring, string\u003e | null;\n  readonly format?: 'amd' | 'iife' | 'umd' | null;\n  readonly name?: string | null;\n  readonly id?: string | null;\n  readonly extend?: boolean | null;\n  readonly globals?: Record\u003cstring, string\u003e | string[] | null;\n  readonly equals?: boolean | null;\n  readonly min?: SelectiveMinOption;\n  readonly skip?: SelectiveSkipOption;\n  readonly project?: SelectiveStringOption;\n}\n```\n\nSee options [`input`](#option-input), [`sourcemap`](#option-sourcemap), [`esModule`](#option-esmodule), [`interop`](#option-interop), [`cache`](#option-cache), [`chunks`](#option-chunks), [`format`](#option-format), [`name`](#option-name), [`id`](#option-id), [`extend`](#option-extend), [`globals`](#option-globals), [`equals`](#option-equals), [`min`](#option-min), [`skip`](#option-skip) and [`project`](#option-project), and types [`SelectiveStringOption`](#type-selectivestringoption), [`SelectiveSourcemapOption`](#type-selectivesourcemapoption), [`SelectiveEsModuleOption`](#type-selectiveesmoduleoption), [`SelectiveInteropOption`](#type-selectiveinteropoption), [`SelectiveMinOption`](#type-selectiveminoption) and [`SelectiveSkipOption`](#type-selectiveskipoption).\n\n### type `PkgAnalyzed`\n\n```typescript\ninterface PkgAnalyzed {\n  cwd: string;\n  pkg: PkgJson;\n  main: ModuleBuildOptions | null;\n  module: ModuleBuildOptions | null;\n  browser: BrowserBuildOptions | null;\n  bin: ModuleBuildOptions | null;\n  types: TypesBuildOptions | null;\n  chunks: Record\u003cstring, string\u003e | null;\n  dependencies: {\n    runtime: PkgJsonDependencies | null;\n    dev: PkgJsonDependencies | null;\n    peer: PkgJsonDependencies | null;\n  };\n  cache: string | null;\n  isInstalled: (id: string) =\u003e string | undefined;\n  installed: {\n    babel: { id: '@babel/core'; version: string } | null;\n    eslint: { id: 'eslint'; version: string } | null;\n    chokidar: { id: 'chokidar'; version: string } | null;\n    typescript: { id: 'typescript'; version: string } | null;\n  };\n}\n```\n\nSee [`ModuleBuildOptions`](#type-modulebuildoptions), [`BrowserBuildOptions`](#type-browserbuildoptions) and [`TypesBuildOptions`](#type-browserbuildoptions)\n\n### type `ModuleBuildOptions`\n\n```typescript\ninterface ModuleBuildOptions {\n  input: string | null;\n  output: string;\n  sourcemap: boolean | 'inline' | 'hidden';\n  esModule: boolean | 'if-default-prop';\n  interop: boolean | 'compat' | 'auto' | 'esModule' | 'default' | 'defaultOnly';\n  min: boolean;\n  project: string | null;\n}\n```\n\n### type `BrowserBuildOptions`\n\n```typescript\ninterface BrowserBuildOptions extends ModuleBuildOptions {\n  format: 'iife' | 'amd' | 'umd';\n  name: string | null;\n  id: string | null;\n  globals: Record\u003cstring, string\u003e | null;\n  extend: boolean;\n}\n```\n\nSee [`ModuleBuildOptions`](#type-modulebuildoptions).\n\n### type `TypesBuildOptions`\n\n```typescript\ninterface TypesBuildOptions {\n  output: string;\n  equals: boolean;\n}\n```\n\n### type `BundlibAPIOptions`\n\n```typescript\nexport interface BundlibAPIOptions {\n  dev?: boolean;\n  watch?: boolean;\n  onwarn?: rollup.WarningHandlerWithDefault;\n}\n```\n\n## Selective Types\n\n### type `SelectiveValueBasedOption`\n\n```typescript\ntype SelectiveValueBasedOption\u003cK extends string, V\u003e = ValueBasedSelectiveOption\u003cK, 'api' | 'default', V\u003e;\n```\n\nSee [`ValueBasedSelectiveOption`](https://github.com/manferlo81/selective-option?tab=readme-ov-file#type-valuebasedselectiveoption) on [selective-option](https://github.com/manferlo81/selective-option) module.\n\n### type `SelectiveBoolBasedOption`\n\n```typescript\ntype SelectiveBoolBasedOption\u003cK extends string, V\u003e = BoolBasedSelectiveOption\u003cK, 'api', V, 'default'\u003e;\n```\n\nSee [`BoolBasedSelectiveOption`](https://github.com/manferlo81/selective-option?tab=readme-ov-file#type-boolbasedselectiveoption) on [selective-option](https://github.com/manferlo81/selective-option) module.\n\n### type `BuildType`\n\n```typescript\ntype BuildType =  'main' | 'module' | 'browser' | 'bin';\n```\n\n### type `SelectiveStringOption`\n\n```typescript\ntype SelectiveStringOption = SelectiveValueBasedOption\u003cBuildType, string\u003e;\n```\n\nSee [`SelectiveValueBasedOption`](#type-selectivevaluebasedoption) and [`BuildType`](#type-buildtype).\n\n### type `SelectiveSourcemapOption`\n\n```typescript\ntype SelectiveSourcemapOption = SelectiveBoolBasedOption\u003cBuildType, 'inline' | 'hidden'\u003e;\n```\n\nSee [`SelectiveBoolBasedOption`](#type-selectiveboolbasedoption) and [`BuildType`](#type-buildtype).\n\n### type `SelectiveEsModuleOption`\n\n```typescript\ntype SelectiveEsModuleOption = SelectiveBoolBasedOption\u003cBuildType, 'if-default-prop'\u003e;\n```\n\nSee [`SelectiveBoolBasedOption`](#type-selectiveboolbasedoption) and [`BuildType`](#type-buildtype).\n\n### type `SelectiveInteropOption`\n\n```typescript\ntype SelectiveInteropOption = SelectiveBoolBasedOption\u003cBuildType, 'default' | 'esModule' | 'compat' | 'auto' | 'defaultOnly'\u003e;\n```\n\nSee [`SelectiveBoolBasedOption`](#type-selectiveboolbasedoption) and [`BuildType`](#type-buildtype).\n\n### type `SelectiveMinOption`\n\n```typescript\ntype SelectiveMinOption = SelectiveBoolBasedOption\u003cBuildType, never\u003e;\n```\n\nSee [`SelectiveBoolBasedOption`](#type-selectiveboolbasedoption) and [`BuildType`](#type-buildtype)\n\n### type `SelectiveSkipOption`\n\n```typescript\ntype SelectiveSkipBuildType = BuildType | 'types';\ntype SelectiveSkipOption = SelectiveBoolBasedOption\u003cSelectiveSkipBuildType, never\u003e;\n```\n\nSee [`SelectiveBoolBasedOption`](#type-selectiveboolbasedoption) and [`BuildType`](#type-buildtype)\n\n## Plugin Notes\n\n### plugin `@rollup/plugin-eslint`\n\nBecause `@rollup/plugin-eslint` uses it's own version of `eslint` (maybe not the same version you are using in your project), you may need to use the `\"overrides\"` property of your `package.json` to ensure `@rollup/plugin-eslint` uses the same version you are using inside your project.\n\n```json\n{\n  \"devDependencies\": {\n    \"eslint\": \"^9.10.0\"\n  },\n  \"overrides\": {\n    \"eslint\": \"^9.10.0\"\n  }\n}\n```\n\n### plugin `rollup-plugin-typescript2`\n\nSome values from your `tsconfig.json` file `\"compilerOptions\"` will be ignored or overridden by `Bundlib`.\n\n#### `\"module\"`\n\n`\"module\"` option will be set to `\"ESNext\"`.\n\n#### `\"sourceMap\"`\n\n`\"sourceMap\"` option will be set according to your [`sourcemap` option](#option-sourcemap) or it's default value.\n\n#### `\"declaration\"`, `\"declarationDir\"` and `\"declarationMap\"`\n\n`\"declaration\"` and `\"declarationDir\"` will be set according to your settings, trying to ensure it follows your `package.json` and configuration. `\"declarationMap\"` will be set to `true` if your declaration files are being emitted.\n\n## Features\n\n* Uses `\"main\"` field in your `package.json` to build a `CommonJS Module`.\n* Uses `\"module\"` field in your `package.json` (or `\"jsnext:main\"` field) to build an `ES Module`.\n* Uses `\"browser\"` field in your `package.json` to build a `Browser` module. It only supports `\"browser\"` field as `string`, `object` format not supported.\n* Uses `\"bin\"` field in your `package.json` to build a `Binary` module. It only supports `\"bin\"` field as `string`, `object` format not supported.\n* Uses `\"types\"` field in your `package.json` (or `\"typings\"` field) as path for types declarations.\n* Uses `\"dependencies\"` and `\"peerDependencies\"` to set external modules for `CommonJS Module`, `ES Module` and `Binary` builds. Dependencies will be bundled by default in `Browser` builds, unless otherwise specified using the [`global`](#option-globals) option.\n* Skip any build based on [options](#option-skip).\n* Uses [`rollup-plugin-typescript2`](https://www.npmjs.com/package/rollup-plugin-typescript2) if [`typescript`](https://www.npmjs.com/package/typescript) installed as runtime or dev dependency.\n* Uses [`@rollup/plugin-babel`](https://www.npmjs.com/package/@rollup/plugin-babel) if [`@babel/core`](https://www.npmjs.com/package/@babel/core) installed as runtime or dev dependency, otherwise it uses [`@rollup/plugin-buble`](https://www.npmjs.com/package/@rollup/plugin-buble).\n* Uses [`rollup-plugin-strip-shebang`](https://www.npmjs.com/package/rollup-plugin-strip-shebang) and [`rollup-plugin-add-shebang`](https://www.npmjs.com/package/rollup-plugin-add-shebang) to ensure a shebang on binary build.\n* Uses [`@rollup/plugin-json`](https://www.npmjs.com/package/@rollup/plugin-json) to import JSON files.\n* Uses[`@rollup/plugin-eslint`](https://www.npmjs.com/package/@rollup/plugin-eslint) if [`eslint`](https://www.npmjs.com/package/eslint) installed as runtime or dev dependency.\n* Uses [`@rollup/plugin-terser`](https://www.npmjs.com/package/@rollup/plugin-terser) to minify production build.\n* Uses [`chokidar`](https://www.npmjs.com/package/chokidar) for file watch if installed.\n\n## Future Features\n\n* Honor `\"type\"` field in `package.json`\n* Honor `\"exports\"` field in `package.json`\n* Support `package.json` `\"bin\"` field as an object for multiple cli commands\n\n## Known issues\n\n* Type declarations for chunks created using the [`chunks`](#option-chunks) option may not work properly.\n\n## License\n\n[MIT](LICENSE) \u0026copy; 2019-2024 [Manuel Fernández](https://github.com/manferlo81)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanferlo81%2Fbundlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanferlo81%2Fbundlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanferlo81%2Fbundlib/lists"}