Skip to content

Commit b059759

Browse files
committed
perf(devframe): dedupe immer between the node and browser builds
node/storage.ts and node/rpc-shared-state.ts reach devframe/utils/shared-state through the same tsconfig path alias the browser build's own utils/shared-state entry uses - two independent rolldown graphs, so each was inlining its own copy of immer (dist/storage-*.mjs and dist/shared-state-*.mjs, ~38 KB and ~33 KB). Add devframe/utils/shared-state to the node build's deps.neverBundle so it's externalized instead of resolved through the tsconfig path alias; the emitted import resolves at runtime to the already-built dist/utils/shared-state.mjs chunk via Node's package self-reference (the client build runs first in the same tsdown invocation, so the chunk exists on disk by the time the node build needs it). Verified end-to-end: built dist/node/index.mjs's createStorage() round-trips through the self-referencing import correctly, and immer's bytes now appear in exactly one dist chunk.
1 parent 512342d commit b059759

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

packages/devframe/tsdown.config.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ const deps = {
5454
],
5555
}
5656

57+
// The node build reaches `devframe/utils/shared-state` (`node/storage.ts`,
58+
// `node/rpc-shared-state.ts`) through the same `devframe/utils/shared-state`
59+
// tsconfig path alias the browser build's own `utils/shared-state` entry
60+
// uses — two independent rolldown graphs, so left alone each would inline
61+
// its own copy of `immer`. Externalizing the specifier here (node build
62+
// only) keeps the tsconfig-paths resolver from ever inlining that source;
63+
// the emitted `import 'devframe/utils/shared-state'` instead resolves at
64+
// runtime to the already-built `dist/utils/shared-state.mjs` chunk via
65+
// Node's package self-reference, so immer's bytes exist exactly once.
66+
const nodeDeps = {
67+
...deps,
68+
neverBundle: [...deps.neverBundle, 'devframe/utils/shared-state'],
69+
}
70+
5771
// Shared by the runtime client build and the combined dts build below.
5872
const clientEntries = {
5973
'client/index': 'src/client/index.ts',
@@ -154,7 +168,7 @@ export default defineConfig([
154168
clean: false,
155169
platform: 'node',
156170
tsconfig,
157-
deps,
171+
deps: nodeDeps,
158172
dts: false,
159173
entry: serverEntries,
160174
},

0 commit comments

Comments
 (0)