-
Notifications
You must be signed in to change notification settings - Fork 85
/
rollup.config.js
105 lines (94 loc) · 3.36 KB
/
rollup.config.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
import jsonPlugin from '@rollup/plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import { tmpdir } from 'node:os';
import { fileURLToPath } from 'node:url';
import { builtinModules } from 'node:module';
import { join as pathJoin } from 'node:path';
const MODULES = [
'vk-io',
'hear',
'scenes',
'session',
'streaming',
'authorization',
'stateless-prompt'
];
const coreModules = builtinModules.filter(name => (
!/(^_|\/)/.test(name)
));
const cacheRoot = pathJoin(tmpdir(), '.rpt2_cache');
const getModulePath = path => (
pathJoin(
fileURLToPath(new URL('.', import.meta.url)),
'packages',
path
)
);
export default async () => (
Promise.all(
MODULES
.map(getModulePath)
.map(async (modulePath) => {
const modulePkg = await import(
pathJoin(modulePath, 'package.json'),
{
with: {
type: 'json'
}
},
);
const src = pathJoin(modulePath, 'src');
const lib = pathJoin(modulePath, 'lib');
return {
input: pathJoin(src, 'index.ts'),
plugins: [
jsonPlugin(),
typescriptPlugin({
cacheRoot,
useTsconfigDeclarationDir: false,
tsconfigOverride: {
outDir: lib,
rootDir: src,
include: [src]
}
}),
// https://rollupjs.org/guide/en/#renderdynamicimport
{
name: 'retain-import-expression',
resolveDynamicImport(specifier) {
if (specifier === 'node-fetch') return false;
return null;
},
renderDynamicImport({ targetModuleId }) {
if (targetModuleId === 'node-fetch') {
return {
left: 'import(',
right: ')'
};
}
return undefined;
}
}
],
external: [
...Object.keys(modulePkg.dependencies || {}),
...Object.keys(modulePkg.peerDependencies || {}),
// TODO: To make better
...MODULES.map(moduleName => `@vk-io/${moduleName}`),
...coreModules
],
output: [
{
file: pathJoin(lib, 'index.js'),
format: 'cjs',
exports: 'named'
},
{
file: pathJoin(lib, 'index.mjs'),
format: 'esm'
}
]
};
})
)
);