-
Notifications
You must be signed in to change notification settings - Fork 13
/
rollup.config.js
87 lines (81 loc) · 2.58 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
import path from 'path';
import fs from 'fs';
import tslib from 'tslib';
import ts from 'typescript';
import { topologicallySort, listWorkspaces } from 'yarn-workspaces-list';
import typescript from 'rollup-plugin-typescript2';
import del from 'rollup-plugin-delete';
import copy from 'rollup-plugin-copy';
import resolve from '@rollup/plugin-node-resolve';
const excludedWorkspaces = ['.'];
const extensions = ['.ts', '.tsx', '.d.ts'];
const commonExternal = ['react/jsx-runtime'];
export default async () => {
const packages = await listWorkspaces();
const filteredPackages = packages.filter(
({ location }) => !excludedWorkspaces.includes(location),
);
const sortedPackages = topologicallySort(filteredPackages);
const config = sortedPackages.map((packageData) => {
const packageDir = packageData.location;
const packageJson = JSON.parse(
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf-8'),
);
const { dependencies, peerDependencies } = packageJson;
const external = [
...commonExternal,
...Object.keys({ ...dependencies, ...peerDependencies }),
];
const cjsDir = path.join(packageDir, path.dirname(packageJson.main));
const esmDir = path.join(packageDir, path.dirname(packageJson.module));
return {
input: path.join(packageDir, 'src/index'),
output: [
{
dir: cjsDir,
preserveModulesRoot: path.join(packageDir, 'src'),
preserveModules: true,
format: 'cjs',
exports: 'named',
},
{
dir: esmDir,
preserveModulesRoot: path.join(packageDir, 'src'),
preserveModules: true,
format: 'es',
exports: 'named',
},
],
plugins: [
del({ targets: path.join(packageDir, 'dist/*'), runOnce: true }),
copy({
targets: [
{
src: path.join(packageDir, 'src/generated/*.d.ts'),
dest: [
path.join(cjsDir, 'generated'),
path.join(esmDir, 'generated'),
],
},
],
copyOnce: true,
}),
resolve({ extensions }),
typescript({
tslib,
typescript: ts,
tsconfig: path.join(packageDir, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
paths: { tslib: [require.resolve('tslib/tslib.d.ts')] },
},
exclude: ['node_modules', 'dist', '**/*.test.*'],
include: ['src/**/*'],
},
}),
],
external,
};
});
return config;
};