This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
65 lines (57 loc) · 1.61 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 babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
const createBabelConfig = require('./babel.config');
const { root } = path.parse(process.cwd());
const extensions = ['.js', '.ts', '.tsx'];
function external(id) {
return !id.startsWith('.') && !id.startsWith(root);
}
function getBabelOptions(targets) {
const config = createBabelConfig({ env: (env) => env === 'build' }, targets);
if (targets.ie) {
config.plugins = [
...config.plugins,
'@babel/plugin-transform-regenerator',
['@babel/plugin-transform-runtime', { helpers: true, regenerator: true }],
];
config.babelHelpers = 'runtime';
}
return {
...config,
extensions,
};
}
function createPluginConfig(targets) {
return [
resolve({ extensions }),
typescript({ useTsconfigDeclarationDir: true }),
babel(getBabelOptions(targets)),
sizeSnapshot(),
terser(),
];
}
function createESMConfig(input, output) {
return {
input,
output: { file: output, format: 'esm' },
plugins: createPluginConfig({ node: 8 }),
external,
};
}
function createCommonJSConfig(input, output) {
return {
input,
preserveModules: true,
output: { dir: output, format: 'cjs', exports: 'named' },
plugins: createPluginConfig({ ie: 11 }),
external,
};
}
export default [
createESMConfig('src/index.ts', 'dist/index.esm.js'),
createCommonJSConfig('src/index.ts', 'dist'),
];