Skip to content

Commit 3e7852e

Browse files
authored
build(replay): Generate Replay CDN bundles (#6391)
Add a rollup config to generate an addon CDN bundle for the Replay integration. Usage of this bundle is identical to our other integration CDN bundles in the sense that the bundle has to be added in addition to the regular browser (or browser+tracing) bundle. As of this PR, three bundles will be generated into `build/bundles`: * `replay.js` (the unminified bundle with debug output) * `replay.min.js`(the minified bundle without debug output) * `replay.debug.min.js` (the minified bundle with debug output) For now, we'll only generate ES6 bundles but we can add ES5 versions if requested later on.
1 parent 11661fa commit 3e7852e

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

.size-limit.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ module.exports = [
6363
gzip: true,
6464
limit: '100 KB',
6565
},
66-
// This entry is only here temporarily and will be replaced once we have proper CDN bundles
6766
{
68-
name: '@sentry/replay index.js',
69-
path: 'packages/replay/build/npm/esm/index.js',
67+
name: '@sentry/replay ES6 CDN Bundle (gzipped + minified)',
68+
path: 'packages/replay/build/bundles/replay.min.js',
7069
gzip: true,
7170
limit: '100 KB',
7271
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
@@ -79,12 +78,4 @@ module.exports = [
7978
limit: '100 KB',
8079
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
8180
},
82-
{
83-
name: '@sentry/replay - Webpack (minified)',
84-
path: 'packages/replay/build/npm/esm/index.js',
85-
import: '{ Replay }',
86-
gzip: false,
87-
limit: '300 KB',
88-
ignore: ['@sentry/browser', '@sentry/utils', '@sentry/core', '@sentry/types'],
89-
},
9081
];

packages/replay/package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
"types": "build/npm/types/index.d.ts",
88
"sideEffects": false,
99
"scripts": {
10+
"build": "run-s build:worker && run-p build:core build:types build:bundle",
1011
"build:rollup": "run-s build:worker build:core",
11-
"build": "run-s build:worker && run-p build:core build:types",
12-
"build:dev": "run-s build #TODO adjust after adding CDN bundles",
12+
"build:bundle": "rollup -c rollup.bundle.config.js",
13+
"build:dev": "run-p build:worker build:rollup build:types",
1314
"build:worker": "rollup -c rollup.config.worker.js",
1415
"build:core": "rollup -c rollup.npm.config.js",
1516
"build:types": "tsc -p tsconfig.types.json",
16-
"build:watch": "run-p \"build:worker --watch\" \"build:core --watch\" build:types:watch",
17-
"build:dev:watch": "yarn build:watch #TODO adjust after adding CDN bundles",
17+
"build:watch": "run-p build:worker:watch build:core:watch build:bundle:watch build:types:watch",
18+
"build:dev:watch": "run-p build:core:watch build:types:watch",
19+
"build:core:watch": "yarn build:core --watch",
20+
"build:worker:watch": "yarn build:worker --watch",
21+
"build:bundle:watch": "yarn build:bundle --watch",
1822
"build:types:watch": "tsc -p tsconfig.types.json --watch",
1923
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
2024
"circularDepCheck": "madge --circular src/index.ts",
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import commonjs from '@rollup/plugin-commonjs';
2+
import replace from '@rollup/plugin-replace';
3+
4+
import { makeBaseBundleConfig, makeBundleConfigVariants } from '../../rollup/index.js';
5+
6+
import pkg from './package.json';
7+
8+
const baseBundleConfig = makeBaseBundleConfig({
9+
bundleType: 'addon',
10+
entrypoints: ['src/index.ts'],
11+
jsVersion: 'es6',
12+
licenseTitle: '@sentry/replay',
13+
outputFileBase: () => 'bundles/replay',
14+
packageSpecificConfig: {
15+
plugins: [
16+
replace({
17+
preventAssignment: true,
18+
values: {
19+
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
20+
},
21+
}),
22+
// lodash.debounce is a CJS module, so we need to convert it to ESM first
23+
commonjs(),
24+
],
25+
},
26+
});
27+
28+
const builds = makeBundleConfigVariants(baseBundleConfig);
29+
30+
export default builds;

packages/replay/src/constants.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { GLOBAL_OBJ } from '@sentry/utils';
22

3-
// exporting WINDOW from within the @sentry/replay instead of importing it from @sentry/browser
4-
// this avoids the Browser package being bundled into the CDN bundle as well as a
5-
// circular dependency between the Browser and Replay packages in the future
3+
// exporting a separate copy of `WINDOW` rather than exporting the one from `@sentry/browser`
4+
// prevents the browser package from being bundled in the CDN bundle, and avoids a
5+
// circular dependency between the browser and replay packages should `@sentry/browser` import
6+
// from `@sentry/replay` in the future
67
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;
78

89
export const REPLAY_SESSION_KEY = 'sentryReplaySession';

packages/replay/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { deleteSession } from './session/deleteSession';
2323
import { getSession } from './session/getSession';
2424
import { saveSession } from './session/saveSession';
2525
import { Session } from './session/Session';
26-
import {
26+
import type {
2727
AllPerformanceEntry,
2828
InstrumentationTypeBreadcrumb,
2929
InstrumentationTypeSpan,

0 commit comments

Comments
 (0)