Skip to content

Smaller bundle#7013

Draft
gonzaloriestra wants to merge 24 commits intomainfrom
smaller-bundle
Draft

Smaller bundle#7013
gonzaloriestra wants to merge 24 commits intomainfrom
smaller-bundle

Conversation

@gonzaloriestra
Copy link
Contributor

@gonzaloriestra gonzaloriestra commented Mar 13, 2026

WHY are these changes introduced?

The bundle is too heavy

WHAT is this pull request doing?

Reduces CLI bundle size by ~89% (62 MB7 MB)

  • Disable source maps (~35.7 MB saved, stack traces still readable)
  • Enable esbuild minifyWhitespace and minifyIdentifiers (~18.8 MB saved)
  • Replace brotli JS package with native zlib.brotliCompressSync (~5.9 MB saved)
  • Externalize 30+ large runtime dependencies (prettier, ts-morph, typescript, polaris, react-dom, vscode language services, @opentelemetry, ink/react, @oclif/core, etc.) (~55 MB saved)
  • Exclude 11 .test.ts files that were accidentally bundled as entry points (~348 KB saved)

How to test your changes?

  • npm i -g @shopify/cli@0.0.0-snapshot-20260313171105
  • shopify app dev
  • shopify theme dev

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

… — saves ~5,904 KB\n\nResult: {"status":"keep","bundle_kb":125332,"js_kb":46412,"maps_kb":74152,"assets_kb":4768}
…784, maps: -2,328)\n\nResult: {"status":"keep","bundle_kb":111220,"js_kb":34628,"maps_kb":71824,"assets_kb":4768}
…ings)\n\nResult: {"status":"keep","bundle_kb":99508,"js_kb":30844,"maps_kb":63896,"assets_kb":4768}
…. Already lazy-loaded via dynamic import.\n\nResult: {"status":"keep","bundle_kb":76368,"js_kb":22848,"maps_kb":48752,"assets_kb":4768}
…ble at runtime as project dep.\n\nResult: {"status":"keep","bundle_kb":57192,"js_kb":16500,"maps_kb":35924,"assets_kb":4768}
…dable (identifiers not minified).\n\nResult: {"status":"keep","bundle_kb":21440,"js_kb":16500,"maps_kb":172,"assets_kb":4768}
…36)\n\nResult: {"status":"keep","bundle_kb":16776,"js_kb":11836,"maps_kb":172,"assets_kb":4768}
…,132 KB\n\nResult: {"status":"keep","bundle_kb":15644,"js_kb":10704,"maps_kb":172,"assets_kb":4768}
…s 524 KB\n\nResult: {"status":"keep","bundle_kb":15120,"js_kb":10180,"maps_kb":172,"assets_kb":4768}
… KB\n\nResult: {"status":"keep","bundle_kb":14128,"js_kb":9188,"maps_kb":172,"assets_kb":4768}
…conciler@0.29.2) — saves 424 KB\n\nResult: {"status":"keep","bundle_kb":13704,"js_kb":8764,"maps_kb":172,"assets_kb":4768}
…ed impact)\n\nResult: {"status":"keep","bundle_kb":13592,"js_kb":8652,"maps_kb":172,"assets_kb":4768}
…Result: {"status":"keep","bundle_kb":13176,"js_kb":8236,"maps_kb":172,"assets_kb":4768}
…-parser, @vscode/web-custom-data — saves 1,136 KB\n\nResult: {"status":"keep","bundle_kb":12040,"js_kb":7100,"maps_kb":172,"assets_kb":4768}
…mver, yaml, js-yaml, execa — saves 1,100 KB\n\nResult: {"status":"keep","bundle_kb":10940,"js_kb":6000,"maps_kb":172,"assets_kb":4768}
…eing bundled) — saves 348 KB\n\nResult: {"status":"keep","bundle_kb":10592,"js_kb":5652,"maps_kb":172,"assets_kb":4768}
… 20+ more runtime deps — saves 1,868 KB\n\nResult: {"status":"keep","bundle_kb":8724,"js_kb":3784,"maps_kb":172,"assets_kb":4768}
@gonzaloriestra
Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 77.24% 14565/18857
🟡 Branches 70.88% 7227/10196
🟡 Functions 76.21% 3701/4856
🟡 Lines 78.73% 13767/17487

Test suite run success

3806 tests passing in 1462 suites.

Report generated by 🧪jest coverage report action from 696e5f7

@gonzaloriestra
Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260313171105

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

'is-executable',
'macaddress',
'network-interfaces',
'diff',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, putting all dependencies as external defeats the purpose of a bundle 😅

Comment on lines +163 to +178
@@ -53,14 +175,14 @@ esBuild({
},
inject: ['../../bin/bundling/cjs-shims.js'],
external,
sourcemap: true,
sourcemap: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need sourcemaps for Observe. They are not included in the final bundle though (they shouldn't at least)

Copy link
Contributor Author

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260317160706

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

esBuild({
bundle: true,
entryPoints: ['./src/**/*.ts'],
entryPoints: (await glob('./src/**/*.ts')).filter(f => !f.includes('.test.')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry point can be simplified to ['./src/index.ts']

inject: ['../../bin/bundling/cjs-shims.js'],
external,
sourcemap: true,
sourcemap: 'external',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Comment on lines +24 to +32
// prettier is ~4MB and only used for formatting generated types.
// Lazily loaded via dynamic import, safe to externalize.
'prettier',
// ts-morph + typescript are ~19MB. Used by Hydrogen for JS/TS transpilation.
// Already lazily loaded via dynamic import, safe to externalize.
'ts-morph',
// typescript compiler (~9MB) is pulled in by ts-morph and json-schema-to-typescript.
// Available at runtime as a project dependency.
'typescript',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making this external means that they are need to be installed by npm, so they don't count for the "bundle size", but this is actually slower because npm needs to find them, resolve them, and download them.

We should only mark as external dependencies that are incompatible with bundling (like esbuild)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants