-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
rollup.config.js
96 lines (89 loc) · 2.58 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
import * as fs from 'fs';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
const terserInstance = terser({
mangle: {
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.
// We need those full names to correctly detect our internal frames for stripping.
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
properties: false,
},
output: {
comments: false,
},
});
const plugins = [
typescript({
tsconfig: 'tsconfig.esm.json',
tsconfigOverride: {
compilerOptions: {
declaration: false,
declarationMap: false,
paths: {
'@sentry/utils': ['../utils/src'],
'@sentry/core': ['../core/src'],
'@sentry/hub': ['../hub/src'],
'@sentry/types': ['../types/src'],
'@sentry/minimal': ['../minimal/src'],
},
baseUrl: '.',
},
},
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
}),
resolve({
mainFields: ['module'],
}),
commonjs(),
];
function mergeIntoSentry() {
return `
__window.Sentry = __window.Sentry || {};
__window.Sentry.Integrations = __window.Sentry.Integrations || {};
for (var key in exports) {
if (Object.prototype.hasOwnProperty.call(exports, key)) {
__window.Sentry.Integrations[key] = exports[key];
}
}
`;
}
function allIntegrations() {
return fs.readdirSync('./src').filter(file => file != 'index.ts');
}
function loadAllIntegrations() {
const builds = [];
[
{
extension: '.js',
plugins,
},
{
extension: '.min.js',
plugins: [...plugins, terserInstance],
},
].forEach(build => {
builds.push(
...allIntegrations().map(file => ({
input: `src/${file}`,
output: {
banner: '(function (__window) {',
intro: 'var exports = {};',
outro: mergeIntoSentry(),
footer: '}(window));',
file: `build/${file.replace('.ts', build.extension)}`,
format: 'cjs',
sourcemap: true,
strict: false,
},
plugins: build.plugins,
treeshake: 'smallest',
})),
);
});
return builds;
}
export default loadAllIntegrations();