-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
104 lines (95 loc) · 2.64 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
import path from 'path';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
const PKG_ROOT = process.cwd();
const PKG = require(path.join(PKG_ROOT, 'package.json'));
const configs = [];
const external = ['fs', 'path', 'redux-saga/effects'];
const createConfig = (input, output, tsconfigOverride) => ({
input,
external: [
...external,
...Object.keys(PKG.dependencies || {}),
...Object.keys(PKG.peerDependencies || {}),
],
output,
plugins: [
resolve(),
commonjs(),
replace({
exclude: 'node_modules/**',
VERSION: PKG.version,
delimiters: ['<@ ', ' @>'],
preventAssignment: true,
}),
typescript({
cacheRoot: `${require('temp-dir')}/.rpt2_cache`,
typescript: require('typescript'),
tslib: require('tslib'),
useTsconfigDeclarationDir: true,
tsconfig: path.join(PKG_ROOT, '/tsconfig.json'),
tsconfigOverride,
}),
],
});
console.log(`\nBuilding ${PKG.name}`);
if (PKG.module) {
configs.push(
createConfig(
'./src/index.ts',
{
file: PKG.module,
format: 'es',
},
{ compilerOptions: { declaration: true } }
)
);
}
if (PKG.main) {
configs.push(
createConfig(
'./src/index.ts',
{
file: PKG.main,
format: 'cjs',
},
{ compilerOptions: { declaration: true } }
)
);
}
if (PKG.bin && typeof PKG.bin === 'string') {
configs.push(
createConfig(
'',
{
file: PKG.bin,
format: 'cjs',
banner: '#!/usr/bin/env node\n',
},
{ compilerOptions: { declaration: true, target: 'es5' } }
)
);
} else if (PKG.bin) {
Object.keys(PKG.bin)
.map(key => PKG.bin[key])
.forEach(bin => {
configs.push(
createConfig(
bin.replace(/\.\/bin\/(.+)\.js/, './src/$1.ts'),
{
file: bin,
format: 'cjs',
banner: '#!/usr/bin/env node\n',
},
{ compilerOptions: { declaration: true, target: 'es5' } }
)
);
});
}
if (!configs.length) {
console.error('Missing rollup configs');
process.exit(1);
}
export default configs;