Commit 7b1b863
authored
fix(sdk-commands): stop bundling a second copy of @dcl/ecs into every scene (#1450)
* fix(sdk-commands): stop bundling a second copy of @dcl/ecs into every scene
The runtime script embedded into scenes as ~sdk/script-utils imported
@dcl/ecs/dist-cjs. EntityState is a runtime enum, so the import survives into
the bundle and drags the whole CommonJS build of ecs (~319 KB minified) in
next to the ESM build the rest of the scene already uses. Importing @dcl/ecs
resolves both to the same ESM copy.
A standard production scene drops from 650 KB to 355 KB (-45%); a scene on
the published SDK 7.24.4 drops from 668 KB to 361 KB. The CLI still uses
dist-cjs where it runs under Node - that was the convention this file
followed (#584), correct there but costly inside bundles (#1245).
The size-tracked bundle snapshots could not catch this because they build
with --customEntryPoint, which skips script-utils; with-main-function is the
one snapshot that exercises the real path, and its expectation is regenerated
here.
* fix(sdk-commands): keep @dcl/ecs tree-shakeable in scene bundles
Requiring the @dcl/ecs barrel from the embedded runtime script makes
esbuild materialize its full CommonJS namespace, keeping every core
component initializer alive: the engine registers 65 component
definitions instead of the 20 the scene uses, and the per-frame CRDT
dirty sweep doubles. Import the types as type-only and the one runtime
value, EntityState, from the dist-cjs leaf (engine/entity.js plus its
single dependency, ~2 KB minified), so the barrel stays import-only and
shakeable and the compiled file stays requirable under Node.
with-main-function vs the previous commit: production bundle 318.6k to
292.2k, eval opcodes 145k to 102k, onUpdate back to the pre-change 5k,
VM memory 1606k to 1301k.1 parent 77493c3 commit 7b1b863
3 files changed
Lines changed: 8 additions & 7 deletions
File tree
- packages/@dcl/sdk-commands/src/logic
- test
- sdk-commands/logic
- snapshots/production-bundles
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
0 commit comments