-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
94 lines (86 loc) · 2.18 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
import { babel } from '@rollup/plugin-babel';
import typescript from 'rollup-plugin-typescript2';
import globals from 'rollup-plugin-node-globals';
import pkg from './package.json';
const input = 'src/index.ts';
const extensions = ['.ts'];
const deps = [].concat(pkg.dependencies ? Object.keys(pkg.dependencies) : []);
function configure(env, target) {
const isModule = target === 'module';
const isCommonJs = target === 'cjs';
const plugins = [
typescript({
abortOnError: false,
tsconfig: './tsconfig.json',
// COMPAT: Without this flag sometimes the declarations are not updated.
// clean: isProd ? true : false,
clean: true,
}),
// Use Babel to transpile the result, limiting it to the source code.
babel({
babelHelpers: 'runtime',
include: ['src/**'],
extensions,
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
exclude: ['@babel/plugin-transform-regenerator', '@babel/transform-async-to-generator'],
modules: false,
targets: {
esmodules: isModule,
},
},
],
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: false,
useESModules: isModule,
},
],
],
}),
// Register Node.js globals for browserify compatibility.
globals(),
].filter(Boolean);
if (isCommonJs) {
return {
plugins,
input,
output: [
{
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
},
],
external: (id) => {
return !!deps.find((dep) => dep === id || id.startsWith(`${dep}/`));
},
};
}
if (isModule) {
return {
plugins,
input,
output: [
{
file: pkg.module,
format: 'es',
sourcemap: true,
},
],
external: (id) => {
return !!deps.find((dep) => dep === id || id.startsWith(`${dep}/`));
},
};
}
}
export default [configure('development', 'cjs'), configure('development', 'module')].filter(
Boolean,
);