Skip to content

Commit e0b1dcc

Browse files
committed
add function to generate bundle config
1 parent 7525490 commit e0b1dcc

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

rollup.config.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
/**
2-
* Shared config used by individual packages' Rollup configs
2+
* Shared config used by individual packages' Rollup configs. Items here come in three flavors:
3+
* - stand-alone: used by `@sentry/browser`, `@sentry/tracing`, and `@sentry/vue` (bundles which are a full SDK in
4+
* and of themselves)
5+
* - add-on: used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone
6+
* SDK bundle)
7+
* - shared: used by both types of bundles
8+
*
39
*/
410

11+
import deepMerge from 'deepmerge';
512
import license from 'rollup-plugin-license';
613
import resolve from '@rollup/plugin-node-resolve';
714
import replace from '@rollup/plugin-replace';
@@ -115,3 +122,61 @@ export const addOnBundleConfig = {
115122
footer: '}(window));',
116123
},
117124
};
125+
126+
export function makeBaseBundleConfig(options) {
127+
const { input, isAddOn, outputFileBase } = options;
128+
129+
const standAloneBundleConfig = {
130+
output: {
131+
format: 'iife',
132+
name: 'Sentry',
133+
},
134+
context: 'window',
135+
};
136+
137+
const addOnBundleConfig = {
138+
// These output settings are designed to mimic an IIFE. We don't use Rollup's `iife` format because we don't want to
139+
// attach this code to a new global variable, but rather inject it into the existing SDK's `Integrations` object.
140+
output: {
141+
format: 'cjs',
142+
143+
// code to add before the CJS wrapper
144+
banner: '(function (__window) {',
145+
146+
// code to add just inside the CJS wrapper, before any of the wrapped code
147+
intro: 'var exports = {};',
148+
149+
// code to add after all of the wrapped code, but still inside the CJS wrapper
150+
outro: () =>
151+
[
152+
'',
153+
" // Add this module's exports to the global `Sentry.Integrations`",
154+
' __window.Sentry = __window.Sentry || {};',
155+
' __window.Sentry.Integrations = __window.Sentry.Integrations || {};',
156+
' for (var key in exports) {',
157+
' if (Object.prototype.hasOwnProperty.call(exports, key)) {',
158+
' __window.Sentry.Integrations[key] = exports[key];',
159+
' }',
160+
' }',
161+
].join('\n'),
162+
163+
// code to add after the CJS wrapper
164+
footer: '}(window));',
165+
},
166+
};
167+
168+
const sharedBundleConfig = {
169+
input,
170+
output: {
171+
// a file extension will be added to this base value when we specify either a minified or non-minified build
172+
file: outputFileBase,
173+
sourcemap: true,
174+
strict: false,
175+
esModule: false,
176+
},
177+
plugins: [typescriptPluginES5, markAsBrowserBuild, nodeResolvePlugin],
178+
treeshake: 'smallest',
179+
};
180+
181+
return deepMerge(sharedBundleConfig, isAddOn ? addOnBundleConfig : standAloneBundleConfig);
182+
}

0 commit comments

Comments
 (0)