From cf3f30e84c79cdb6000873ae416de50350963f41 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 1 Mar 2022 21:10:34 -0800 Subject: [PATCH 1/2] apply __SENTRY_NO_DEBUG__ to all bundles --- rollup.config.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index 6412f0388a37..64956e2c9ecd 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -42,6 +42,13 @@ export function makeLicensePlugin(title) { } export const terserPlugin = 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_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. From 6d850d1114760a38cadae7c8ac14a2f9e81f5be5 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 1 Mar 2022 21:11:51 -0800 Subject: [PATCH 2/2] use config function for browser bundles --- packages/browser/rollup.config.js | 151 ++++++------------------------ 1 file changed, 29 insertions(+), 122 deletions(-) diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js index c1b20f305de1..aff948180f83 100644 --- a/packages/browser/rollup.config.js +++ b/packages/browser/rollup.config.js @@ -1,130 +1,37 @@ -import { terser } from 'rollup-plugin-terser'; -import typescript from 'rollup-plugin-typescript2'; +import { makeBaseBundleConfig, makeLicensePlugin, terserPlugin } from '../../rollup.config'; -import { - baseBundleConfig, - makeLicensePlugin, - markAsBrowserBuild, - nodeResolvePlugin, - paths, - typescriptPluginES5, -} from '../../rollup.config'; +const builds = []; const licensePlugin = makeLicensePlugin(); -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_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 plugins = [ - typescriptPluginES5, - // replace `__SENTRY_BROWSER_BUNDLE__` with `true` to enable treeshaking of non-browser code - markAsBrowserBuild, - nodeResolvePlugin, -]; - -const bundleConfig = { - ...baseBundleConfig, - input: 'src/index.ts', - output: { - ...baseBundleConfig.output, - format: 'iife', - name: 'Sentry', - }, - context: 'window', - plugins: [...plugins, licensePlugin], -}; +['es5', 'es6'].forEach(jsVersion => { + const baseBundleConfig = makeBaseBundleConfig({ + input: 'src/index.ts', + isAddOn: false, + jsVersion, + outputFileBase: `build/bundle${jsVersion === 'es6' ? '.es6' : ''}`, + }); -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', - }, + builds.push( + ...[ + { + ...baseBundleConfig, + output: { + ...baseBundleConfig.output, + file: `${baseBundleConfig.output.file}.js`, }, - 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', - }, + plugins: [...baseBundleConfig.plugins, licensePlugin], + }, + { + ...baseBundleConfig, + output: { + ...baseBundleConfig.output, + file: `${baseBundleConfig.output.file}.min.js`, }, - include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)'], - }), - ...plugins.slice(1).slice(0, -1).concat(terserInstance).concat(bundleConfig.plugins.slice(-1)), + plugins: [...baseBundleConfig.plugins, terserPlugin, licensePlugin], + }, ], - }, - // ------------------ -]; + ); +}); + +export default builds;