|
1 | 1 | /**
|
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 | + * |
3 | 9 | */
|
4 | 10 |
|
| 11 | +import deepMerge from 'deepmerge'; |
5 | 12 | import license from 'rollup-plugin-license';
|
6 | 13 | import resolve from '@rollup/plugin-node-resolve';
|
7 | 14 | import replace from '@rollup/plugin-replace';
|
@@ -115,3 +122,61 @@ export const addOnBundleConfig = {
|
115 | 122 | footer: '}(window));',
|
116 | 123 | },
|
117 | 124 | };
|
| 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