File tree 4 files changed +48
-1
lines changed
4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,14 @@ const commitHash = require('child_process')
9
9
. trim ( ) ;
10
10
11
11
const terserInstance = terser ( {
12
+ compress : {
13
+ // Tell env.ts that we're building a browser bundle and that we do not
14
+ // want to have unnecessary debug functionality.
15
+ global_defs : {
16
+ __SENTRY_BROWSER_BUNDLE__ : true ,
17
+ __SENTRY_NDEBUG__ : true ,
18
+ } ,
19
+ } ,
12
20
mangle : {
13
21
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
14
22
// as mangler doesn't touch user-facing thing, however sentryWrapped is not, and it would be mangled into a minified version.
Original file line number Diff line number Diff line change
1
+ /**
2
+ * This module mostly exists for optimizations in the build process
3
+ * through rollup and terser. We define some global constants which
4
+ * are normally undefined. However terser overrides these with global
5
+ * definitions which can be evaluated by the static analyzer when
6
+ * creating a bundle.
7
+ *
8
+ * In turn the `isDebugBuild` and `isBrowserBundle` functions are pure
9
+ * and can help us remove unused code from the bundles.
10
+ */
11
+
12
+ declare const __SENTRY_BROWSER_BUNDLE__ : boolean | undefined ;
13
+ declare const __SENTRY_NDEBUG__ : boolean | undefined ;
14
+
15
+ /**
16
+ * Figures out if we're building with debug functionality.
17
+ *
18
+ * @returns true if this is a debug build
19
+ */
20
+ export function isDebugBuild ( ) : boolean {
21
+ return ! __SENTRY_NDEBUG__ ;
22
+ }
23
+
24
+ /**
25
+ * Figures out if we're building a browser bundle.
26
+ *
27
+ * @returns true if this is a browser bundle build.
28
+ */
29
+ export function isBrowserBundle ( ) : boolean {
30
+ return ! ! __SENTRY_BROWSER_BUNDLE__ ;
31
+ }
Original file line number Diff line number Diff line change @@ -17,3 +17,4 @@ export * from './string';
17
17
export * from './supports' ;
18
18
export * from './syncpromise' ;
19
19
export * from './time' ;
20
+ export * from './env' ;
Original file line number Diff line number Diff line change 3
3
* you must either a) use `console.log` rather than the logger, or b) put your function elsewhere.
4
4
*/
5
5
6
+ import { isBrowserBundle } from './env' ;
7
+
6
8
/**
7
9
* Checks whether we're in the Node.js or Browser environment
8
10
*
9
11
* @returns Answer to given question
10
12
*/
11
13
export function isNodeEnv ( ) : boolean {
12
- return Object . prototype . toString . call ( typeof process !== 'undefined' ? process : 0 ) === '[object process]' ;
14
+ // explicitly check for browser bundles as those can be optimized statically
15
+ // by terser/rollup.
16
+ return (
17
+ ! isBrowserBundle ( ) &&
18
+ Object . prototype . toString . call ( typeof process !== 'undefined' ? process : 0 ) === '[object process]'
19
+ ) ;
13
20
}
14
21
15
22
/**
You can’t perform that action at this time.
0 commit comments