-
Notifications
You must be signed in to change notification settings - Fork 166
Description
We are using the @datadog/browser-logs, @datadog/browser-rum npm libraries and noticed that they are not being properly tree-shaken in our build. As a result, a large amount of unused code (thousands of lines) is included in the final bundle.
The root cause appears to be side effects introduced at module scope. For example, in the following file:
https://github.com/DataDog/browser-sdk/blob/main/packages/logs/src/entries/main.ts#L60
The lines below introduce side effects during import:
export const datadogLogs = makeLogsPublicApi(startLogs)
defineGlobal(getGlobalObject<BrowserWindow>(), 'DD_LOGS', datadogLogs)
which prevents effective tree-shaking by bundlers.
This behavior makes it difficult to exclude unused functionality and leads to unnecessary bundle size increase.
To Reproduce
Steps to reproduce the behavior:
Just add imports
import { datadogRum } from '@datadog/browser-rum';
import { datadogLogs } from '@datadog/browser-logs/';
and you will end up adding thousands of line of code in your bundle.
Expected behavior
Bundle should only contain functions which is getting used.