UNPKG

3.91 kBMarkdownView Raw
1[npm]: https://img.shields.io/npm/v/@rollup/plugin-multi-entry
2[npm-url]: https://www.npmjs.com/package/@rollup/plugin-multi-entry
3[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-multi-entry
4[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-multi-entry
5
6[![npm][npm]][npm-url]
7[![size][size]][size-url]
8[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
9
10# @rollup/plugin-multi-entry
11
12🍣 A Rollup plugin which allows use of multiple entry points for a bundle.
13
14As an added bonus, the _named exports_ from all entry points will be combined. This is particularly useful for tests, but can also be used to package a library.
15
16_Note: `default` exports cannot be combined and exported by this plugin. Only named exports will be exported._
17
18## Requirements
19
20This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.3.0+) and Rollup v1.20.0+.
21
22## Install
23
24Using npm:
25
26```console
27npm install @rollup/plugin-multi-entry --save-dev
28```
29
30## Usage
31
32Suppose that we have three separate source files, each with their own export(s):
33
34```js
35// batman.js
36export const belt = 'utility';
37```
38
39```js
40// robin.js
41export const tights = 'tight';
42```
43
44```js
45// joker.js
46export const color = 'purple';
47```
48
49Then, create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
50
51```js
52import multi from '@rollup/plugin-multi-entry';
53
54export default {
55 input: ['batman.js', 'robin.js', 'joker.js'],
56 output: {
57 dir: 'output'
58 },
59 plugins: [multi()]
60};
61```
62
63Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
64
65Using all three files above as entry points will yield a bundle with exports for `belt`, `tights`, and `color`.
66
67## Options
68
69### `exports`
70
71Type: `Boolean`<br>
72Default: `true`
73
74If `true`, instructs the plugin to export named exports to the bundle from all entries. If `false`, the plugin will not export any entry exports to the bundle. This can be useful when wanting to combine code from multiple entry files, but not necessarily to export each entry file's exports.
75
76### `entryFileName`
77
78Type: `String`<br>
79Default: `'multi-entry.js'`
80
81`entryFileName` changes the name of the generated entry file. By default, it will override `outputOptions.entryFileNames` to be `'multi-entry.js'`.
82
83## Supported Input Types
84
85This plugin extends Rollup's `input` option to support multiple new value types, in addition to a `String` specifying a path to a file.
86
87### Glob
88
89When using `plugin-multi-entry`, input values passed as a normal `String` are [glob aware](<https://en.wikipedia.org/wiki/Glob_(programming)>). Meaning you can utilize glob wildcards and other glob patterns to specify files as being input files.
90
91```js
92export default {
93 input: 'batcave/friends/**/*.js',
94 plugins: [multi()]
95 // ...
96};
97```
98
99### Array
100
101An `Array` of `String` can be passed as the input. Values are glob-aware and can specify paths or globbed paths.
102
103```js
104export default {
105 input: ['party/supplies.js', 'batcave/friends/**/*.js'],
106 plugins: [multi()]
107 // ...
108};
109```
110
111### `include` and `exclude`
112
113For fine-grain control, an `Object` may be passed containing `include` and `exclude` properties. These properties specify and `Array` of `String` representing paths (which are also glob-aware) which should be included as entry files, as well as files that should be excluded from any entries that may have been found with `include`, respectively.
114
115```js
116export default {
117 input: {
118 // invite everyone!
119 include: ['food.js', 'drinks.js', 'batcave/friends/**/*.js'],
120 // except for the joker
121 exclude: ['**/joker.js']
122 },
123 plugins: [multi()]
124 // ...
125};
126```
127
128## Meta
129
130[CONTRIBUTING](/.github/CONTRIBUTING.md)
131
132[LICENSE (MIT)](/LICENSE)