UNPKG

1.54 kBJavaScriptView Raw
1import { promise } from 'matched';
2
3var entry = '\0rollup-plugin-multi-entry:entry-point';
4
5function multiEntry() {
6 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
7
8 var include = [];
9 var exclude = [];
10 var exporter = function exporter(path) {
11 return 'export * from ' + JSON.stringify(path) + ';';
12 };
13
14 function configure(config) {
15 if (typeof config === 'string') {
16 include = [config];
17 } else if (Array.isArray(config)) {
18 include = config;
19 } else {
20 include = config.include || [];
21 exclude = config.exclude || [];
22 if (config.exports === false) {
23 exporter = function exporter(path) {
24 return 'import ' + JSON.stringify(path) + ';';
25 };
26 }
27 }
28 }
29
30 if (config) {
31 configure(config);
32 }
33
34 return {
35 options: function options(_options) {
36 if (_options.input && _options.input !== entry) {
37 configure(_options.input);
38 }
39 _options.input = entry;
40 },
41 resolveId: function resolveId(id) {
42 if (id === entry) {
43 return entry;
44 }
45 },
46 load: function load(id) {
47 if (id === entry) {
48 if (!include.length) {
49 return Promise.resolve('');
50 }
51 var patterns = include.concat(exclude.map(function (pattern) {
52 return '!' + pattern;
53 }));
54 return promise(patterns, { realpath: true }).then(function (paths) {
55 return paths.map(exporter).join('\n');
56 });
57 }
58 }
59 };
60}
61
62export default multiEntry;