-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
65 lines (62 loc) · 1.66 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
import typescript from 'rollup-plugin-typescript2';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'node:fs';
// foreach packages
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const packagesDir = path.resolve(__dirname, 'packages');
const packages = fs.readdirSync(packagesDir).filter((f) => {
if (!fs.statSync(path.join(packagesDir, f)).isDirectory()) {
return false;
}
if (!fs.existsSync(path.join(packagesDir, f, 'package.json'))) {
return false;
}
if (!fs.existsSync(path.join(packagesDir, f, 'src/index.ts'))) {
return false;
}
return true;
});
// sort packages, gopeed-types should be first
packages.sort((a, b) => {
if (a === 'gopeed-types') {
return -1;
}
if (b === 'gopeed-types') {
return 1;
}
return a.localeCompare(b);
});
export default packages.map((pkgName) => {
const pkg = JSON.parse(fs.readFileSync(path.join(packagesDir, pkgName, 'package.json'), 'utf-8'));
return {
input: `packages/${pkgName}/src/index.ts`,
output: [
{
file: `packages/${pkgName}/dist/index.cjs`,
format: 'cjs',
sourcemap: false,
},
{
file: `packages/${pkgName}/dist/index.js`,
format: 'esm',
sourcemap: false,
},
],
plugins: [
resolve(),
commonjs(),
typescript({
tsconfigOverride: {
compilerOptions: {
declaration: true,
},
include: [`packages/${pkgName}/src`],
},
}),
],
external: Object.keys(pkg.dependencies || {}),
};
});