forked from MylesBorins/node-osc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
92 lines (85 loc) · 1.91 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { readdirSync as readdir, statSync as stat } from 'fs';
// Borrowed from the rollup docs
// https://github.com/rollup/rollup/blob/d0db53459be43c5cc806cb91f14e82217950ba42/docs/05-plugin-development.md#renderdynamicimport
function retainImportExpressionPlugin() {
return {
name: 'retain-import-expression',
resolveDynamicImport(specifier) {
if (specifier === 'get-port') return false;
return null;
},
renderDynamicImport({ targetModuleId }) {
if (targetModuleId === 'get-port') {
return {
left: 'import(',
right: ')'
};
}
}
};
}
function walk(root, result=[]) {
const rootURL = new URL(root, import.meta.url);
const paths = readdir(rootURL);
for (const path of paths) {
const stats = stat(new URL(path, rootURL));
if (stats.isDirectory()) {
walk(`${root}${path}/`, result);
}
else {
result.push({
input: `${root}${path}`,
dir: `dist/${root}`
});
}
}
return result;
}
function walkLib(config) {
const files = walk('./lib/');
files.forEach(({input, dir}) => {
config.push({
input,
output: {
entryFileNames: '[name].js',
dir,
format: 'cjs',
exports: 'auto'
},
preserveModules: true,
external: [
'dgram',
'events',
'osc-min',
'jspack'
]
});
});
}
function walkTest(config) {
const tests = walk('./test/');
tests.forEach(({input, dir}) => {
config.push({
input,
plugins: [retainImportExpressionPlugin()],
output: {
entryFileNames: '[name].js',
dir,
format: 'cjs',
exports: 'auto'
},
preserveModules: true,
external: [
'dgram',
'get-port',
'node-osc',
'osc-min',
'tap'
]
})
});
}
const config = [];
walkLib(config);
walkTest(config);
export default config;