-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrollup.config.js
86 lines (79 loc) · 2.01 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
import lernaJson from './lerna.json';
import path from 'path';
import fs from 'fs';
import glob from 'glob';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import shebang from 'rollup-plugin-preserve-shebang';
import scss from 'rollup-plugin-scss';
const availableFormatOutputs = [
{ format: 'cjs', key: 'main' },
{ format: 'esm', key: 'module' },
];
const finalConfig = lernaJson.packages
.reduce((configs, globPattern) => {
return [
...configs,
...glob.sync(globPattern).map((packagePath) => {
const packageFullPath = path.resolve(__dirname, packagePath);
const rollupConfigPath = path.resolve(
packageFullPath,
'rollup.config.js'
);
if (fs.existsSync(rollupConfigPath)) {
return require(rollupConfigPath)({
path,
plugins: {
babel,
commonjs,
peerDepsExternal,
scss,
shebang,
},
});
}
const packageJson = require(path.resolve(
packageFullPath,
'package.json'
));
return {
input: path.resolve(
packageFullPath,
packageJson.source || 'src/index.js'
),
external: (id) => {
const dependencies = [
...(packageJson.dependencies
? Object.keys(packageJson.dependencies)
: []),
...(packageJson.peerDependencies
? Object.keys(packageJson.peerDependencies)
: []),
];
return dependencies.some(
(dependency) => id.indexOf(dependency) === 0
);
},
output: availableFormatOutputs
.filter(({ key }) => packageJson.hasOwnProperty(key))
.map(({ format, key }) => ({
file: path.resolve(
packageFullPath,
packageJson[key]
),
format,
sourcemap: true,
})),
plugins: [
babel({ babelHelpers: 'runtime' }),
commonjs(),
peerDepsExternal(),
scss(),
],
};
}),
];
}, [])
.filter((config) => !!config);
export default finalConfig;