Skip to content

fix(build): minify Workers in apps without a meta framework - #981

Draft
hyfdev wants to merge 1 commit into
mainfrom
fix/minify-void-worker
Draft

hyfdev wants to merge 1 commit into
mainfrom
fix/minify-void-worker

Conversation

@hyfdev

@hyfdev hyfdev commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Since #188, Workers in Void apps without a meta framework haven't been minified by default.

Now they are, and function and class names are kept.

JavaScript in a production Worker build, in bytes (each file gzipped, then added up):

App Before: not minified After: minified, names kept Change
React starter 159,126 110,248 -31%
Vue starter 111,633 71,373 -36%
Svelte starter 81,513 48,853 -40%
Solid starter 89,486 57,746 -35%
API with one route, no pages 41,286 24,489 -41%

#188 moved these apps' Worker from Vite's ssr environment to void_worker, but Void's minify: true stayed on ssr.

Code can depend on function and class names, as in this error from an API route added to the Vue starter, along with two test pages:

class DerivedError extends Error {
  constructor(message: string) {
    super(message);
    this.name = this.constructor.name;
  }
}
Vite config Logged before Logged after Gzipped Worker JavaScript, before → after
minify not set DerivedError: … DerivedError: … 117,153 → 75,491
build: { minify: true } l: … l: … 70,597 → 70,597

With minify not set, the stack position of another error thrown in that route moves from 14:8 to 1:342.

The Worker build's source maps, already on by default, place both at line 10 of the route's source.

Vite config, top level or environments.void_worker (output is build.rolldownOptions.output) Before After
neither build.minify nor output.minify is set not minified minified, with all comments removed unless output.comments says otherwise; function and class names kept, except #private names
the same, plus output.keepNames: false not minified minified and comments removed as above, but names shortened
any build.minify or output.minify, such as build.minify: false the app's setting no change

Auxiliary Workers, and apps with output: 'static' in void.config.ts, don't change.

Fixes #980.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-minify-void-worker-void-cloud.voidzero-docs.workers.dev (commit d57f11e)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://ff3232bb-void-cloud.voidzero-docs.workers.dev d57f11e 2026-11-30T02:07:46.035Z Visit the dashboard ↗

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Issue: A later configEnvironment hook that sets output.minify: false still loses @license comments after this change. If the hook sets minify: true, Void swaps in its own name-preserving settings even though the plugin explicitly opted into normal minification. Let's apply the defaults only when the app and its Vite plugins leave minification unset.

This branch has not been deployed

No deployments
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.

Production builds don't minify the Worker in apps without a meta framework

2 participants