diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 6ef09192eef1..83053aaeea98 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -26,6 +26,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' })); +const ignoreSideEffects = /[\\\/]debug-build\.ts$/; + export function makeBaseNPMConfig(options = {}) { const { entrypoints = ['src/index.ts'], @@ -83,6 +85,17 @@ export function makeBaseNPMConfig(options = {}) { interop: 'esModule', }, + treeshake: { + moduleSideEffects: (id, external) => { + if (external === false && ignoreSideEffects.test(id)) { + // Tell Rollup this module has no side effects, so it can be tree-shaken + return false; + } + + return true; + } + }, + plugins: [nodeResolvePlugin, sucrasePlugin, debugBuildStatementReplacePlugin, rrwebBuildPlugin, cleanupPlugin], // don't include imported modules from outside the package in the final output