-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
105 lines (93 loc) · 2.63 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 path from 'path';
import transpile from '@rollup/plugin-buble';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import workspacesRun from 'workspaces-run';
import babel from '@rollup/plugin-babel';
async function main()
{
const plugins = [
sourcemaps(),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
json(),
typescript({ tsconfig: './tsconfig.json' }),
transpile(),
cleanup(),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-env', '@babel/preset-react']
})
];
const compileTime = new Date().toUTCString();
const packages = [];
const results = [];
await workspacesRun({ cwd: __dirname, orderByDeps: true }, async (pkg) =>
{
if (!pkg.config.private)
{
packages.push(pkg);
}
});
packages.forEach((pkg) =>
{
const {
version,
main,
module,
dependencies,
peerDependencies,
} = pkg.config;
if (main === undefined || module === undefined)
{
return;
}
const banner = [
`/*!`,
` * ${pkg.name} - v${version}`,
` * Compiled ${compileTime}`,
` */`,
].join('\n');
const basePath = path.relative(__dirname, pkg.dir);
const sourcemap = true;
const external = Object.keys(dependencies || [])
.concat(Object.keys(peerDependencies || []));
const input = (() => {
if(basePath === 'packages/react'){
return path.join(basePath, 'src/index.tsx');;
}
return path.join(basePath, 'src/index.ts');
})();
const freeze = false;
results.push({
input,
output: [
{
banner,
file: path.join(basePath, main),
format: 'cjs',
freeze,
sourcemap,
},
{
banner,
file: path.join(basePath, module),
format: 'esm',
freeze,
sourcemap,
},
],
external,
plugins,
});
});
return results;
}
export default main();