-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
rollup.config.js
161 lines (155 loc) · 4.36 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import license from 'rollup-plugin-license';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
const commitHash = require('child_process')
.execSync('git rev-parse --short HEAD', { encoding: 'utf-8' })
.trim();
const terserInstance = terser({
compress: {
// Tell env.ts that we're building a browser bundle and that we do not
// want to have unnecessary debug functionality.
global_defs: {
__SENTRY_BROWSER_BUNDLE__: true,
__SENTRY_NO_DEBUG__: false,
},
},
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's sake, as they are all used in the frame-manipulation process.
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
properties: {
regex: /^_[^_]/,
// This exclusion prevents most of the occurrences of the bug linked below:
// https://github.com/getsentry/sentry-javascript/issues/2622
// The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code.
// Unfortunatelly we cannot fix it reliably (thus `typeof` check in the `InboundFilters` code),
// as we cannot force people using multiple instances in their apps to sync SDK versions.
reserved: ['_mergeOptions'],
},
},
output: {
comments: false,
},
});
const paths = {
'@sentry/utils': ['../utils/src'],
'@sentry/core': ['../core/src'],
'@sentry/hub': ['../hub/src'],
'@sentry/types': ['../types/src'],
'@sentry/minimal': ['../minimal/src'],
};
const plugins = [
typescript({
tsconfig: 'tsconfig.esm.json',
tsconfigOverride: {
compilerOptions: {
declaration: false,
declarationMap: false,
paths,
baseUrl: '.',
},
},
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
}),
resolve({
mainFields: ['module'],
}),
commonjs(),
];
const bundleConfig = {
input: 'src/index.ts',
output: {
format: 'iife',
name: 'Sentry',
sourcemap: true,
strict: false,
},
context: 'window',
plugins: [
...plugins,
license({
sourcemap: true,
banner: `/*! @sentry/browser <%= pkg.version %> (${commitHash}) | https://github.com/getsentry/sentry-javascript */`,
}),
],
treeshake: 'smallest',
};
export default [
// ES5 Browser Bundle
{
...bundleConfig,
output: {
...bundleConfig.output,
file: 'build/bundle.js',
},
},
{
...bundleConfig,
output: {
...bundleConfig.output,
file: 'build/bundle.min.js',
},
// Uglify has to be at the end of compilation, BUT before the license banner
plugins: bundleConfig.plugins
.slice(0, -1)
.concat(terserInstance)
.concat(bundleConfig.plugins.slice(-1)),
},
// ------------------
// ES6 Browser Bundle
{
...bundleConfig,
output: {
...bundleConfig.output,
file: 'build/bundle.es6.js',
},
plugins: [
typescript({
tsconfig: 'tsconfig.esm.json',
tsconfigOverride: {
compilerOptions: {
declaration: false,
declarationMap: false,
paths,
baseUrl: '.',
target: 'es6',
},
},
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
}),
...plugins.slice(1).concat(bundleConfig.plugins.slice(-1)),
],
},
{
...bundleConfig,
output: {
...bundleConfig.output,
file: 'build/bundle.es6.min.js',
},
plugins: [
typescript({
tsconfig: 'tsconfig.esm.json',
tsconfigOverride: {
compilerOptions: {
declaration: false,
declarationMap: false,
paths,
baseUrl: '.',
target: 'es6',
},
},
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
}),
...plugins
.slice(1)
.slice(0, -1)
.concat(terserInstance)
.concat(bundleConfig.plugins.slice(-1)),
],
},
// ------------------
];