UNPKG

5.2 kBMarkdownView Raw
1# Bundlib
2
3[![CircleCI](https://circleci.com/gh/manferlo81/bundlib.svg?style=svg)](https://circleci.com/gh/manferlo81/bundlib) [![Greenkeeper badge](https://badges.greenkeeper.io/manferlo81/bundlib.svg)](https://greenkeeper.io/) [![npm](https://img.shields.io/npm/v/bundlib.svg)](https://www.npmjs.com/package/bundlib) [![dependencies Status](https://david-dm.org/manferlo81/bundlib/status.svg)](https://david-dm.org/manferlo81/bundlib) [![devDependencies Status](https://david-dm.org/manferlo81/bundlib/dev-status.svg)](https://david-dm.org/manferlo81/bundlib?type=dev) [![install size](https://packagephobia.now.sh/badge?p=bundlib)](https://packagephobia.now.sh/result?p=bundlib) [![Known Vulnerabilities](https://snyk.io/test/github/manferlo81/bundlib/badge.svg?targetFile=package.json)](https://snyk.io/test/github/manferlo81/bundlib?targetFile=package.json) [![License](https://img.shields.io/github/license/manferlo81/bundlib.svg)](https://github.com/manferlo81/bundlib/blob/master/LICENSE)
4
5A Zero-configuration, automatic javascript library bundler using [Typescript](#) and [Rollup.js](#).
6
7> :warning: Bundlib is still under active development, if you find any issue/bug please open a new issue.
8
9## Install
10
11* as a dev dependency
12
13```sh
14npm i bundlib -D
15```
16
17* or install it globally if you wish
18
19```sh
20npm i bundlib -g
21```
22
23## First steps
24Bundlib will use `src/index.ts` as entry file for your library by default, make sure you create it before you try to build. Add the corresponding scripts to your `package.json` ([see below for CLI options](#cli)) and run them.
25
26## CommonJS module
27
28Building a `CommonJS Module` is as simple as creating a `"main"` field in `package.json` pointing to the output file, and `bundlib` will build it for you.
29
30## ES module
31
32To build a `ES Module` simply add a `"module"` field in `package.json` pointing to the output file.
33
34## IIFE, AMD and UMD build
35
36For IIFE, AMD and UMD builds you will need to use the `"bundlib"` field in `package.json`, see the [configuration section](#configuration) for more info.
37
38## Configuration
39
40Configuration is done throu the `"bundlib"` field in `package.json`.
41
42### Example
43
44The following example will generate a **UMD** build in `my-lib.umd.js` file inside the `dist` folder, then you can use the library in the browser (for example) using the global `myLib` (`window.myLib`).
45
46```javascript
47// package.json
48{
49 "version": "1.0.0",
50 "name": "my-lib",
51 // ...
52 "bundlib": {
53 "name": "myLib",
54 "umd": "dist/my-lib.umd.js"
55 }
56 // ...
57}
58```
59
60### Options
61
62the `"bundlib"` field in `package.json` may contain any of the following properties.
63
64#### input
65
66* *used in:* `all builds`
67* *type:* `string`
68* *defaults to* `"src/index.ts"`
69
70*the path to the input file*
71
72#### sourcemap
73
74* *used in:* `all builds`
75* *type:* `boolean`
76* *defaults to* `true`
77
78*whether to generate source maps*
79
80#### esModule
81
82* *used in:* `CommonJS, IIFE, AMD & UMD builds`
83* *type:* `boolean`
84* *defaults to* `false`
85
86*whether to add a* `esModule` *property to your build.*
87
88#### interop
89
90* *used in:* `CommonJS, IIFE, AMD & UMD builds`
91* *type:* `boolean`
92* *defaults to* `false`
93
94#### name
95
96* *used in:* `IIFE, AMD & UMD builds`
97* *type:* `string`
98* *required for:* `IIFE, AMD & UMD builds`
99
100*the* `IIFE`, `AMD` or `UMD` *name*
101
102#### id
103
104* *used in:* `AMD & UMD builds`
105* *type:* `string`
106
107*optional amd id for* `AMD` or `UMD` *build.*
108> *if not present,* `AMD` *module will be defined with no id.*
109
110#### extend
111
112* *used in:* `IIFE, AMD & UMD builds`
113* *type:* `boolean`
114* *defaults to* `false`
115
116*whether to extend the name on an* `IIFE`, `AMD` or `UMD` *build.*
117
118#### globals
119
120* *used in:* `IIFE, AMD & UMD builds`
121* *type:* `object`
122
123*object to map names to globals*
124
125#### iife
126
127* *type:* `string`
128
129*the output path for* `IIFE` *build.*
130> *if not present,* `IIFE` *build will be skipped.*
131
132#### amd
133
134* *type:* `string`
135
136*the output path for* `AMD` *build.*
137> *if not present,* `AMD` *build will be skipped.*
138
139#### umd
140
141* *type:* `string`
142
143*the output path for* `UMD` *build.*
144> *if not present,* `UMD` *build will be skipped.*
145
146#### equals
147
148* *used in:* `types for CommonJS build`
149* *type:* `boolean`
150* *defaults to* `false`
151
152*fixes type export for CommonJS module using* `module.exports = ...`
153
154> :warning: note that this options should only be used when your library has a default export and no named exports.
155
156## CLI
157
158```sh
159bundlib [options]
160```
161
162Bundlib has only two options
163
164* `-d`, `--dev` : *creates a development, not minified builds.*
165* `-w`, `--watch` : *runs* `bundlib` *in watch mode.*
166
167> Combine your options according to your needs.
168
169## Features
170
171* [x] Creates a CommonJS Module based on the `"main"` field in `package.json`
172* [x] Creates an ES Modules based on the `"module"` field in `package.json`
173* [x] Exports types declarations based on the `"typings"` or `"types"` field in your `package.json`
174* [x] Creates IIFE, AMD and UMD builds using the `"bundlib"` field in your `package.json`, see [configuration section](#configuration) for more info.
175* [x] Transforms async/await using [Babel](#) and [babel-plugin-transform-async-to-promises](#) for ES5 support
176* [x] Transforms using [Buble](#)
177
178## License
179
180MIT License