UNPKG

7.33 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) [![codecov](https://codecov.io/gh/manferlo81/bundlib/branch/master/graph/badge.svg)](https://codecov.io/gh/manferlo81/bundlib) [![License](https://img.shields.io/github/license/manferlo81/bundlib.svg)](LICENSE)
4
5A Zero-configuration, automatic javascript library bundler using [Typescript](https://github.com/Microsoft/TypeScript) and [Rollup.js](https://github.com/rollup/rollup).
6
7> :warning: Bundlib is still under active development, please [file a new issue](https://github.com/manferlo81/bundlib/issues) if you find any issue/bug, suggestions are welcome as well.
8
9## Install
10
11##### as a dev dependency
12
13```bash
14npm i bundlib -D
15```
16
17##### or install it globally if you wish
18
19```bash
20npm i bundlib -g
21```
22
23## First steps
24
25Bundlib 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.
26
27## Build
28
29### CommonJS module
30
31Building a `CommonJS Module` is as simple as adding a `"main"` field to your `package.json` pointing to the output file, and `bundlib` will build it for you. see the [configuration section](#configuration) for some extra options.
32
33### ES module
34
35To build a `ES Module` simply add a `"module"` field to your `package.json` pointing to the output file. see the [configuration section](#configuration) for some extra options.
36
37### IIFE, AMD and UMD build
38
39For IIFE, AMD and 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 `browser` option, see the [configuration section](#configuration) for more info.
40
41## Configuration
42
43Configuration is done throu the `"bundlib"` field in `package.json`.
44
45##### Example
46
47The following example will generate a **AMD** build with filename `my-lib.amd.js` inside the `dist` folder, then you can use the library in the browser (for example) using the global `myLib` (`window.myLib`).
48
49```javascript
50// package.json
51{
52 "version": "1.0.0",
53 "name": "my-lib",
54 "browser" : "dist/my-lib.amd.js",
55 // ...
56 "bundlib": {
57 "name": "myLib",
58 "browser": "amd"
59 }
60 // ...
61}
62```
63
64### Options
65
66the `"bundlib"` field in `package.json` may contain any of the following properties.
67
68#### input
69
70* *used in:* `all builds`
71* *type:* `string`
72* *defaults to* `"src/index.ts"`
73
74*the path to the input file, it has to be a* `.ts` *file*
75
76> *allowing javascript (*`.js`*) files as input is comming soon*
77
78#### sourcemap
79
80* *used in:* `all builds`
81* *type:* `boolean`
82* *defaults to* `true`
83
84*whether or not to generate source maps*
85
86#### esModule
87
88* *used in:* `CommonJS, IIFE, AMD & UMD builds`
89* *type:* `boolean`
90* *defaults to* `false`
91
92*whether or not to add a* `__esModule: true` *property to your non-es-module build.*
93
94#### interop
95
96* *used in:* `CommonJS, IIFE, AMD & UMD builds`
97* *type:* `boolean`
98* *defaults to* `false`
99
100*whether or not to add an interop block*
101
102#### browser
103
104* *added in* `v0.3.0`
105* *type:* `"iife" | "amd" | "umd"`
106* *defaults to* `"umd"`
107
108*defines the format to be used for the* `browser` *build*
109
110#### name
111
112* *used in:* `IIFE, AMD & UMD builds`
113* *type:* `string`
114* *required for:* `IIFE, AMD & UMD builds`
115
116*the* `IIFE`, `AMD` or `UMD` *name*
117
118*if not provided it will default to* `"name"` *field in* `package.json` *, if it doesn't exist the build process will throw*
119
120#### id
121
122* *used in:* `AMD & UMD builds`
123* *type:* `string`
124
125*optional amd id for* `AMD` or `UMD` *build.*
126
127> *if not present,* `AMD` *module will be defined with no id.*
128
129#### extend
130
131* *used in:* `IIFE, AMD & UMD builds`
132* *type:* `boolean`
133* *defaults to* `false`
134
135*whether or not to extend the global exported variable on an* `IIFE`, `AMD` or `UMD` *build.*
136
137#### globals
138
139* *used in:* `IIFE, AMD & UMD builds`
140* *type:* `object`
141
142*object to map names to globals*
143
144#### equals
145
146* *added in* `v0.1.0`
147* *used in:* `types for CommonJS build`
148* *type:* `boolean`
149* *defaults to* `false`
150
151*fixes type export for CommonJS module using* `export = ...` instead of `export default ...`
152
153> :warning: note that this options should only be used when your library has a default export and no named exports.
154
155#### min
156
157* *added in* `v0.3.2`
158* `boolean` *support added in* `v0.4.1`
159* *used in:* `all builds`
160* *type:* `"main" | "module" | "browser" | boolean | Array<"main" | "module" | "browser">`
161
162*Defines which module to build an aditional minified version, if* `true` *will affect all modules. The minified file will be renamed from* `*.ext` to `*.min.ext`.
163
164> *In* `v0.4.0` *the behavior of this option slightly changed. Output modules affected by this option won't be minified, even if the* [`dev`](#-dev-d) *cli option hasn\'t been set.*
165
166### Deprecated Options
167
168#### iife
169
170* *deprecated in* `v0.3.0`*, use* [browser option](#browser) *instead.*
171* *type:* `string`
172
173*the output path for* `IIFE` *build.*
174> *if not present,* `IIFE` *build will be skipped.*
175
176#### amd
177
178* *deprecated in* `v0.3.0`*, use* [browser option](#browser) *instead.*
179* *type:* `string`
180
181*the output path for* `AMD` *build.*
182> *if not present,* `AMD` *build will be skipped.*
183
184#### umd
185
186* *deprecated in* `v0.3.0`*, use* [browser option](#browser) *instead.*
187* *type:* `string`
188
189*the output path for* `UMD` *build.*
190> *if not present,* `UMD` *build will be skipped.*
191
192
193## CLI
194
195```bash
196bundlib [options]
197```
198
199### Options
200
201*Bundlib has only three options...*
202
203#### --dev, -d
204
205*type:* `boolean`
206
207*creates a development, not minified builds.*
208
209#### --watch, -w
210
211*type:* `boolean`
212
213*runs* `bundlib` *in watch mode.*
214
215#### --silent, -s
216
217*type:* `boolean`
218
219*prevent messages from showing in the console.*
220
221## Known Issues
222
223* [Issue #7](https://github.com/manferlo81/bundlib/issues/7)
224
225## Features
226
227### Current Features
228
229* [x] Creates a CommonJS Module based on the `"main"` field in `package.json`
230* [x] Creates an ES Modules based on the `"module"` field in `package.json`
231* [x] Creates an browser build based on the `"browser"` field in `package.json`
232* [x] Exports types declarations based on the `"typings"` or `"types"` field in your `package.json`
233* [x] Transforms async/await using [Babel](#) and [babel-plugin-transform-async-to-promises](#) for ES5 support
234* [x] Transforms using [Buble](#)
235* [x] Minifies build using [terser](#)
236
237### Upcomming Features
238
239* [ ] Creates an CLI binary build based on the `"bin"` field in `package.json`
240
241## License
242
243[MIT](LICENSE) &copy; Manuel Fernández