-
Notifications
You must be signed in to change notification settings - Fork 10
/
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 path from 'path';
import {readdirSync} from 'readdir-withfiletypes';
import rollupExternalModules from 'rollup-external-modules';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import hashbang from 'rollup-plugin-hashbang';
import json from 'rollup-plugin-json';
import resolve from '@rollup/plugin-node-resolve';
const IGNORED_PACKAGES = ['docs'];
const packagesDir = path.join(__dirname, 'packages');
/**
*
* @param {string} pkgpath - Path to subpackage root
*/
const makeConfigs = pkgpath => {
const pkg = require(`${pkgpath}/package.json`);
const cjsConfig = {
external: rollupExternalModules,
input: require.resolve(`${pkgpath}/${pkg.module}`),
output: {
file: path.join(pkgpath, pkg.main),
format: 'cjs',
sourcemap: true
},
plugins: [
resolve({
preferBuiltins: true
}),
commonjs({
include: [
/node_modules/,
/packages\/common\/src\/configs\/recommended\.js/
]
}),
json(),
babel({
exclude: [path.join(pkgpath, 'node_modules', '**')],
babelHelpers: 'bundled'
})
]
};
/**
* @type {typeof cjsConfig[]}
*/
const configs = [];
if (pkgpath.endsWith('cli') || pkgpath.endsWith('report-toolkit')) {
cjsConfig.plugins.unshift(hashbang());
}
return [...configs, cjsConfig];
};
export default readdirSync(packagesDir, {
withFileTypes: true
})
.filter(dirent => dirent.isDirectory())
// this should be a flatmap
.reduce(
(acc, {name}) =>
!IGNORED_PACKAGES.includes(name)
? [...acc, ...makeConfigs(path.join(packagesDir, name))]
: acc,
[]
);