-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.js
72 lines (63 loc) · 1.71 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
// outsource dependencies
import babel from '@rollup/plugin-babel';
import typescript from 'rollup-plugin-typescript2';
import nodeResolve from '@rollup/plugin-node-resolve';
// local dependencies
import pkg from './package.json';
// configure
const FILE_NAME = 'index';
const INPUT_FILE = 'src/index.ts';
const extensions = ['.ts'];
const noDeclarationFiles = { compilerOptions: { declaration: false } };
const babelRuntimeVersion = pkg.dependencies['@babel/runtime'].replace(/^[^0-9]*/, '');
const makeExternalPredicate = (externalArr) => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return (id) => pattern.test(id);
};
const prepare = ({ input, output, format, tsconfig, babelconfig }) => ({
input,
output: { file: `${output}/${FILE_NAME}.js`, format, indent: false },
external: makeExternalPredicate([
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]),
plugins: [
nodeResolve({ extensions }),
typescript(tsconfig),
babel(babelconfig),
],
});
export default [
// CommonJS
prepare({
input: INPUT_FILE,
output: 'lib',
format: 'cjs',
tsconfig: { useTsconfigDeclarationDir: true },
babel: {
extensions,
plugins: [
['@babel/plugin-transform-runtime', { version: babelRuntimeVersion }],
],
}
}),
// ES
prepare({
input: INPUT_FILE,
output: 'es',
format: 'es',
tsconfig: { tsconfigOverride: noDeclarationFiles },
babel: {
extensions,
plugins: [
[
'@babel/plugin-transform-runtime',
{ version: babelRuntimeVersion, useESModules: true },
],
],
}
}),
];