Skip to content

Commit 1494709

Browse files
committed
feat(core): split exports by browser/server for bundle size
Split the exports from `@sentry/core` into three options: - `@sentry/core`, the default (unchanged) - `@sentry/core/browser`, containing _only_ shared and browser-specific functionality, nothing server-specific. - `@sentry/core/server`, containing _only_ shared and server-specific functionality, nothing browser-specific. This should allow us to make the bundle sizes quite a bit smaller in our browser SDKs where this is important, while adding more functionality to our server-specific SDKs, in `@sentry/core` where they can be easily shared across runtimes. Integration may require updating our `tsconfig` settings so that tsc knows it is allowed to look on `package.json` exports. fix: #20434 fix: JS-2243
1 parent 8ad3dd0 commit 1494709

12 files changed

Lines changed: 672 additions & 608 deletions

File tree

packages/core/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@
1717
"types": "build/types/index.d.ts",
1818
"exports": {
1919
"./package.json": "./package.json",
20+
"./server": {
21+
"import": {
22+
"types": "./build/types/server.d.ts",
23+
"default": "./build/esm/server.js"
24+
},
25+
"require": {
26+
"types": "./build/types/server.d.ts",
27+
"default": "./build/cjs/server.js"
28+
}
29+
},
30+
"./browser": {
31+
"import": {
32+
"types": "./build/types/browser.d.ts",
33+
"default": "./build/esm/browser.js"
34+
},
35+
"require": {
36+
"types": "./build/types/browser.d.ts",
37+
"default": "./build/cjs/browser.js"
38+
}
39+
},
2040
".": {
2141
"import": {
2242
"types": "./build/types/index.d.ts",

packages/core/rollup.npm.config.mjs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@ if (!packageJson.version) {
1414

1515
const packageVersion = packageJson.version;
1616

17+
const settings = {
18+
packageSpecificConfig: {
19+
output: {
20+
// set exports to 'named' or 'auto' so that rollup doesn't warn
21+
exports: 'named',
22+
// set preserveModules to true because we don't want to bundle everything into one file.
23+
preserveModules:
24+
process.env.SENTRY_BUILD_PRESERVE_MODULES === undefined
25+
? true
26+
: Boolean(process.env.SENTRY_BUILD_PRESERVE_MODULES),
27+
},
28+
plugins: [
29+
replace({
30+
preventAssignment: true,
31+
values: {
32+
__SENTRY_SDK_VERSION__: JSON.stringify(packageVersion),
33+
},
34+
}),
35+
],
36+
},
37+
};
38+
1739
export default makeNPMConfigVariants(
1840
makeBaseNPMConfig({
19-
packageSpecificConfig: {
20-
output: {
21-
// set exports to 'named' or 'auto' so that rollup doesn't warn
22-
exports: 'named',
23-
// set preserveModules to true because we don't want to bundle everything into one file.
24-
preserveModules:
25-
process.env.SENTRY_BUILD_PRESERVE_MODULES === undefined
26-
? true
27-
: Boolean(process.env.SENTRY_BUILD_PRESERVE_MODULES),
28-
},
29-
plugins: [
30-
replace({
31-
preventAssignment: true,
32-
values: {
33-
__SENTRY_SDK_VERSION__: JSON.stringify(packageVersion),
34-
},
35-
}),
36-
],
37-
},
41+
...settings,
42+
entrypoints: ['src/index.ts', 'src/server.ts', 'src/browser.ts'],
3843
}),
3944
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Browser-only: DOM utilities
2+
export { getComponentName, getLocationHref, htmlTreeAsString } from './utils/browser';
3+
4+
// Browser-only: feature detection for browser APIs
5+
export { supportsDOMError, supportsHistory, supportsNativeFetch, supportsReportingObserver } from './utils/supports';
6+
7+
// Browser-only: XHR and DOM breadcrumb types
8+
export type { XhrBreadcrumbData, XhrBreadcrumbHint } from './types-hoist/breadcrumb';
9+
10+
// Browser-only: XHR and DOM handler types
11+
export type {
12+
HandlerDataXhr,
13+
HandlerDataDom,
14+
HandlerDataHistory,
15+
SentryXhrData,
16+
SentryWrappedXMLHttpRequest,
17+
} from './types-hoist/instrument';
18+
19+
// Browser-only: replay and profiling options
20+
export type { BrowserClientReplayOptions, BrowserClientProfilingOptions } from './types-hoist/browseroptions';

packages/core/src/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* eslint-disable max-lines */
2+
3+
export * from './shared-exports';
4+
export * from './browser-exports';

0 commit comments

Comments
 (0)