Skip to content

feat: add svelte-shaker support and remove routes.ts convention in favor of single index.ts#74

Merged
khromov merged 26 commits into
mainfrom
svelte-shaker
Jun 7, 2026
Merged

feat: add svelte-shaker support and remove routes.ts convention in favor of single index.ts#74
khromov merged 26 commits into
mainfrom
svelte-shaker

Conversation

@khromov

@khromov khromov commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

This PR has two themes: svelte-shaker integration and removing the routes.ts convention in favor of a single index.ts entry as the source of truth.

svelte-shaker support

  • Adds optimizeWithSvelteShaker?: boolean | { exclude?: string[]; report?: boolean } to Mochi.serve() and MochiBuildOptions
  • Drives the svelte-shaker engine directly via its Node shell (svelte-shaker/node) — no Vite/Rollup plugin host needed
  • Shaking runs production only (ignored in dev); slims .svelte source via prop folding, dead-branch removal, and CSS narrowing before the Svelte compiler runs
  • exclude globs let callers opt specific components out of shaking (safe: they still count as call sites for others)
  • report logs a per-component size breakdown at build time (scanned vs slimmed counts)
  • Docs page added at packages/docs/177-svelte-shaker.md; unit tests in svelteShaker.test.ts and ComponentRegistry.shake*.test.ts

Single index.ts entry — drop the routes.ts convention

  • Build now reads config straight from the entry's Mochi.serve() call via the new extractServeOptions (a capturing serve() stub), so the prebuilt manifest stays single-sourced with the runtime
  • Removes the legacy --routes CLI flag and the routeModule serve option / auto-discovery of ./src/routes.ts
  • Dev route HMR is now entry-based: the watcher builds the entry to discover its transitive deps, and on change re-extracts routes via extractServeOptions and hot-swaps handlers in place — no restart, no special route module
  • route-module recompile trigger renamed to entry
  • Each app inlines its route map into index.ts; packages/demos/src/routes.ts and packages/minimal/src/routes.ts deleted, packages/site routes split into src/routes.ts imported by index.ts
  • Docs across packages/docs/ updated to the single-entry pattern

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Mochi review report

Try this PR

Expand instructions
gh run download -R khromov/mochi 27104728073 -n mochi-framework-pr -D /tmp/mochi-pr && bun i /tmp/mochi-pr/mochi-framework-pr.tgz

Download manually

Dependency report

Expand report
Direct: 13
Peer:   3 (svelte, @tailwindcss/node, @tailwindcss/oxide)
Dev:    8
Total unique packages reachable from production deps (roots + transitive): 31
Total on-disk size of those packages: 5.39 MB

Toplist — direct deps ranked by total size (self + transitive):
      total       self  count  package
    4.77 MB    2.71 MB     19  svelte
   683.7 kB   137.8 kB      3  svelte-shaker
   534.0 kB   449.0 kB      1  magic-string
   189.0 kB   146.0 kB      1  stale-while-revalidate-cache
   180.6 kB   145.3 kB      1  chokidar
    51.2 kB    51.2 kB      0  devalue
    30.4 kB    30.4 kB      0  deepmerge
    28.0 kB    28.0 kB      0  negotiator
    25.8 kB    25.8 kB      0  mitt
    25.3 kB    25.3 kB      0  js-cookie
    13.4 kB    13.4 kB      0  nanoid
    12.0 kB    12.0 kB      0  zimmerframe
     5.2 kB     5.2 kB      0  @types/negotiator

Transitive breakdown for the heaviest deps:

  svelte (19, 2.05 MB transitive): @jridgewell/gen-mapping (91.6 kB), @jridgewell/remapping (58.0 kB), @jridgewell/resolve-uri (51.9 kB), @jridgewell/sourcemap-codec (85.0 kB), @jridgewell/trace-mapping (143.3 kB), @sveltejs/acorn-typescript (194.2 kB), @types/estree (25.5 kB), @types/trusted-types (8.4 kB), acorn (545.5 kB), aria-query (172.8 kB), axobject-query (108.3 kB), clsx (8.4 kB), devalue (51.2 kB), esm-env (3.7 kB), esrap (86.1 kB), is-reference (3.9 kB), locate-character (5.2 kB), magic-string (449.0 kB), zimmerframe (12.0 kB)

  svelte-shaker (3, 545.9 kB transitive): @jridgewell/sourcemap-codec (85.0 kB), magic-string (449.0 kB), zimmerframe (12.0 kB)

  magic-string (1, 85.0 kB transitive): @jridgewell/sourcemap-codec (85.0 kB)

  stale-while-revalidate-cache (1, 43.0 kB transitive): emittery (43.0 kB)

  chokidar (1, 35.3 kB transitive): readdirp (35.3 kB)

Lines of code

packages/mochi
Category main PR Δ
src/**/*.test.ts 5856 6078 +222
src/Mochi.ts 1223 1221 -2
src/ComponentRegistry.ts 1539 1621 +82
src/build*.ts 250 258 +8
src/cli* 112 120 +8
src/{types.ts,*.d.ts} 650 675 +25
Other 2606 2750 +144
Total 17817 18304 +487

Unchanged: src/hooks.ts (235), src/{requestContext,forms,errors}.ts (298), src/{events,log,logger}.ts (338), src/consoleLogger.ts (358), src/cookies*.ts (157), src/extensions.ts (191), src/cache.ts (60), src/middleware/** (81), src/enhance*.ts (184), src/proxy.ts (125), src/{csrf,serverIslandCrypto}.ts (240), src/web-components/** (445), src/debug-bar/** (2079), src/templates/** (790).

packages/docs
Category main PR Δ
Docs 3602 3743 +141
Total 3602 3743 +141
packages/site
Category main PR Δ
Other 1306 1305 -1
Total 10026 10025 -1

Unchanged: src/demos/** (5633), src/components/** (2120), src/lib/** (941), src/stores/** (26).

packages/demos
Category main PR Δ
Other 2023 2020 -3
Total 3108 3105 -3

Unchanged: src/hn/** (1085).

packages/minimal
Category main PR Δ
Other 538 536 -2
Total 538 536 -2
packages/cli
Category main PR Δ
Total 479 479 0

Unchanged: src/**/*.test.ts (117), src/cli* (138), src/{create,templates,utils}.ts (220), Other (4).

@khromov khromov marked this pull request as ready for review June 6, 2026 21:42
@khromov khromov changed the title feat: add optimizeWithSvelteShaker option for production tree-shaking feat: add svelte-shaker support Jun 7, 2026
@khromov khromov changed the title feat: add svelte-shaker support feat: add svelte-shaker support and remove routes.ts convention in favor of single index.ts Jun 7, 2026
@khromov khromov merged commit ec4487f into main Jun 7, 2026
6 checks passed
@khromov khromov deleted the svelte-shaker branch June 7, 2026 21:08
@github-actions github-actions Bot mentioned this pull request Jun 7, 2026
khromov pushed a commit that referenced this pull request Jun 7, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>mochi-framework: 0.6.0</summary>

##
[0.6.0](mochi-framework-v0.5.1...mochi-framework-v0.6.0)
(2026-06-07)


### Features

* add svelte-shaker support and remove routes.ts convention in favor of
single index.ts ([#74](#74))
([ec4487f](ec4487f))
* added a new "info" tab to debug bar showing runtime versions and mochi
configuration
([a6a1792](a6a1792))


### Bug Fixes

* **mochi-framework:** various hmr edge case fixes
([ecb627d](ecb627d))
* trigger hmr when shell.html is edited
([#72](#72))
([d519b89](d519b89))
* various hmr edge case fixes
([79048e3](79048e3))
</details>

<details><summary>create-mochi: 0.2.4</summary>

##
[0.2.4](create-mochi-v0.2.3...create-mochi-v0.2.4)
(2026-06-07)


### Bug Fixes

* **mochi-framework:** various hmr edge case fixes
([ecb627d](ecb627d))
* various hmr edge case fixes
([79048e3](79048e3))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant