Skip to content

Commit 6ad73e4

Browse files
authored
Enable Rollup treeshaking pass by default, disable only for CLI builds (#944)
1 parent 3d26526 commit 6ad73e4

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

.changeset/pink-peaches-grab.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@codama/cli': patch
3+
'@codama/dynamic-codecs': patch
4+
'@codama/dynamic-parsers': patch
5+
'@codama/errors': patch
6+
'codama': patch
7+
'@codama/node-types': patch
8+
'@codama/nodes': patch
9+
'@codama/nodes-from-anchor': patch
10+
'@codama/renderers-core': patch
11+
'@codama/validators': patch
12+
'@codama/visitors': patch
13+
'@codama/visitors-core': patch
14+
---
15+
16+
Enable Rollup treeshaking pass by default, disable only for CLI builds

packages/cli/tsup.config.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
import { defineConfig } from 'tsup';
1+
import { defineConfig, Options as TsupConfig } from 'tsup';
22

33
import { getBuildConfig, getCliBuildConfig } from '../../tsup.config.base';
44

55
export default defineConfig([
6-
getBuildConfig({ format: 'cjs', platform: 'node' }),
7-
getBuildConfig({ format: 'esm', platform: 'node' }),
8-
getCliBuildConfig(),
6+
removeAdditionalTreeShaking(getBuildConfig({ format: 'cjs', platform: 'node' })),
7+
removeAdditionalTreeShaking(getBuildConfig({ format: 'esm', platform: 'node' })),
8+
removeAdditionalTreeShaking(getCliBuildConfig()),
99
]);
10+
11+
function removeAdditionalTreeShaking(config: TsupConfig): TsupConfig {
12+
return {
13+
...config,
14+
15+
// Treeshaking already happens with esbuild but tsup offers this options
16+
// for "better" treeshaking strategies using Rollup as an additional step.
17+
// The issue is Rollup now uses the deprecated "assert" import keyword by default
18+
// And tsup doesn't offer a way to change this behavior. Since the CLI package
19+
// relies on using the "with" keyword to dynamically import JSON files,
20+
// we can't use Rollup for treeshaking.
21+
treeshake: false,
22+
};
23+
}

tsup.config.base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function getBuildConfig(options: BuildOptions): TsupConfig {
5454
publicDir: true,
5555
pure: ['process'],
5656
sourcemap: format !== 'iife',
57+
treeshake: true,
5758
};
5859
}
5960

0 commit comments

Comments
 (0)