-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
115 lines (109 loc) · 2.82 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
105
106
107
108
109
110
111
112
113
114
115
import babel from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import alias from '@rollup/plugin-alias';
import cleanup from 'rollup-plugin-cleanup';
import typescript from 'rollup-plugin-typescript2';
import license from 'rollup-plugin-license';
import pkg from './package.json';
const path = require('path');
const makeExternalPredicate = () => {
const externalArr = [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
];
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return id => pattern.test(id);
};
const extensions = ['js', 'ts'];
const external = makeExternalPredicate();
const getPlugins = (env) => {
return [
replace({
'SDK_VERSION': JSON.stringify(pkg.version),
'global.': 'window.',
preventAssignment: true
}),
(env === 'browser' && alias({
entries: [
{ find: /.\/node$/, replacement: './browser' }
]
})),
typescript({
// eslint-disable-next-line node/no-unpublished-require
typescript: require('typescript'),
tsconfigOverride: {
compilerOptions: {
sourceMap: true,
target: 'ES2017', // skip async/await transpile,
module: 'ES2020', // support dynamic import
declaration: false
}
}
}),
// not add @babel/runtime import for development
(process.env.NODE_ENV !== 'development' && babel({
babelHelpers: 'runtime',
presets: [
'@babel/preset-env'
],
plugins: [
// https://babeljs.io/docs/en/babel-plugin-transform-runtime#corejs
['@babel/plugin-transform-runtime', {
corejs: 3
}],
],
extensions
})),
cleanup({
extensions,
comments: 'none'
}),
license({
banner: {
content: {
file: path.join(__dirname, 'scripts', 'license-template'),
}
}
})
];
};
export default [
{
input: 'lib/index.ts',
external,
plugins: getPlugins('browser'),
output: [
{
format: 'esm',
file: 'build/esm/esm.browser.js',
exports: 'named',
sourcemap: true
},
// not emit test bundle for development
(process.env.NODE_ENV !== 'development' && {
// generate ems bundle for jest test, ".mjs" extension should be used
// this bundle is excluded from the release package
format: 'esm',
file: 'build/bundles-for-validation/esm/esm.browser.mjs',
exports: 'named',
sourcemap: true
})
]
},
{
input: 'lib/index.ts',
external,
plugins: getPlugins('node'),
output: [
{
format: 'esm',
file: 'build/esm/esm.node.mjs',
exports: 'named',
sourcemap: true
}
]
}
];