Skip to content

Commit 977df6c

Browse files
lobsterkatieAbhiPrasad
authored andcommitted
ref(build): Use rollup config function for @sentry/browser (#4668)
As part of centralizing and unifying our CDN rollup config, this uses the config generation function introduced in #4650 to generate the config for all browser bundles. Unlike many of the other PRs in this series, this one does actually have an effect on certain bundles, to wit: - `_mergeOptions` is no longer a protected-from-minifcation property, as it's about to be extracted into a stand-alone function. (See #4625.) - Up until this point, one difference between the `@sentry/browser` rollup config and all of the other rollup configs was the former's use of the `__SENTRY_NO_DEBUG__` flag to suppress logs in the minified bundles. Rather than add a parameter to the function controlling whether or not each package should use the flag, I decided it was better to just apply the flag to all minified bundles.
1 parent 99a78f7 commit 977df6c

File tree

2 files changed

+36
-122
lines changed

2 files changed

+36
-122
lines changed

packages/browser/rollup.config.js

Lines changed: 29 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,37 @@
1-
import { terser } from 'rollup-plugin-terser';
2-
import typescript from 'rollup-plugin-typescript2';
1+
import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config';
32

4-
import {
5-
baseBundleConfig,
6-
makeLicensePlugin,
7-
markAsBrowserBuild,
8-
nodeResolvePlugin,
9-
paths,
10-
typescriptPluginES5,
11-
} from '../../rollup.config';
3+
const builds = [];
124

135
const licensePlugin = makeLicensePlugin();
146

15-
const terserInstance = terser({
16-
compress: {
17-
// Tell env.ts that we're building a browser bundle and that we do not
18-
// want to have unnecessary debug functionality.
19-
global_defs: {
20-
__SENTRY_NO_DEBUG__: false,
21-
},
22-
},
23-
mangle: {
24-
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
25-
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.
26-
// We need those full names to correctly detect our internal frames for stripping.
27-
// I listed all of them here just for the clarity's sake, as they are all used in the frame-manipulation process.
28-
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
29-
properties: {
30-
regex: /^_[^_]/,
31-
// This exclusion prevents most of the occurrences of the bug linked below:
32-
// https://github.com/getsentry/sentry-javascript/issues/2622
33-
// The bug is caused by multiple SDK instances, where one is minified and one is using non-mangled code.
34-
// Unfortunatelly we cannot fix it reliably (thus `typeof` check in the `InboundFilters` code),
35-
// as we cannot force people using multiple instances in their apps to sync SDK versions.
36-
reserved: ['_mergeOptions'],
37-
},
38-
},
39-
output: {
40-
comments: false,
41-
},
42-
});
43-
44-
const plugins = [
45-
typescriptPluginES5,
46-
// replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code
47-
markAsBrowserBuild,
48-
nodeResolvePlugin,
49-
];
50-
51-
const bundleConfig = {
52-
...baseBundleConfig,
53-
input: 'src/index.ts',
54-
output: {
55-
...baseBundleConfig.output,
56-
format: 'iife',
57-
name: 'Sentry',
58-
},
59-
context: 'window',
60-
plugins: [...plugins, licensePlugin],
61-
};
7+
['es5', 'es6'].forEach(jsVersion => {
8+
const baseBundleConfig = makeBaseBundleConfig({
9+
input: 'src/index.ts',
10+
isAddOn: false,
11+
jsVersion,
12+
outputFileBase: `build/bundle${jsVersion === 'es6' ? '.es6' : ''}`,
13+
});
6214

63-
export default [
64-
// ES5 Browser Bundle
65-
{
66-
...bundleConfig,
67-
output: {
68-
...bundleConfig.output,
69-
file: 'build/bundle.js',
70-
},
71-
},
72-
{
73-
...bundleConfig,
74-
output: {
75-
...bundleConfig.output,
76-
file: 'build/bundle.min.js',
77-
},
78-
// Uglify has to be at the end of compilation, BUT before the license banner
79-
plugins: bundleConfig.plugins.slice(0, -1).concat(terserInstance).concat(bundleConfig.plugins.slice(-1)),
80-
},
81-
// ------------------
82-
// ES6 Browser Bundle
83-
{
84-
...bundleConfig,
85-
output: {
86-
...bundleConfig.output,
87-
file: 'build/bundle.es6.js',
88-
},
89-
plugins: [
90-
typescript({
91-
tsconfig: 'tsconfig.esm.json',
92-
tsconfigOverride: {
93-
compilerOptions: {
94-
declaration: false,
95-
declarationMap: false,
96-
paths,
97-
baseUrl: '.',
98-
target: 'es6',
99-
},
15+
builds.push(
16+
...[
17+
{
18+
...baseBundleConfig,
19+
output: {
20+
...baseBundleConfig.output,
21+
file: `${baseBundleConfig.output.file}.js`,
10022
},
101-
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
102-
}),
103-
...plugins.slice(1).concat(bundleConfig.plugins.slice(-1)),
104-
],
105-
},
106-
{
107-
...bundleConfig,
108-
output: {
109-
...bundleConfig.output,
110-
file: 'build/bundle.es6.min.js',
111-
},
112-
plugins: [
113-
typescript({
114-
tsconfig: 'tsconfig.esm.json',
115-
tsconfigOverride: {
116-
compilerOptions: {
117-
declaration: false,
118-
declarationMap: false,
119-
paths,
120-
baseUrl: '.',
121-
target: 'es6',
122-
},
23+
plugins: [...baseBundleConfig.plugins, licensePlugin],
24+
},
25+
{
26+
...baseBundleConfig,
27+
output: {
28+
...baseBundleConfig.output,
29+
file: `${baseBundleConfig.output.file}.min.js`,
12330
},
124-
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'],
125-
}),
126-
...plugins.slice(1).slice(0, -1).concat(terserInstance).concat(bundleConfig.plugins.slice(-1)),
31+
plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin],
32+
},
12733
],
128-
},
129-
// ------------------
130-
];
34+
);
35+
});
36+
37+
export default builds;

rollup.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export function makeLicensePlugin(title) {
4242
}
4343

4444
export const terserPlugin = terser({
45+
compress: {
46+
// Tell env.ts that we're building a browser bundle and that we do not
47+
// want to have unnecessary debug functionality.
48+
global_defs: {
49+
__SENTRY_NO_DEBUG__: false,
50+
},
51+
},
4552
mangle: {
4653
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
4754
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.

0 commit comments

Comments
 (0)