Repository navigation
The Vite plugin loads all of Miniflare on every build. #17073
workers-devprod
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Moved from #17071. Originally opened by cpojer on 2026-11-20.
I've been looking at where time goes in
vite buildandvite devfor apps that use@cloudflare/vite-plugin. The largest single item is not the build. It is loading Miniflare.The plugin imports Miniflare at the top of its entry point:
That means every command that loads a Vite config with the Cloudflare plugin pays for Miniflare, including
vite build, which never starts a local runtime.Numbers
Measured on an M-series MacBook with Node 24.22.1,
@cloudflare/vite-plugin2.0.0-rc.0 andminiflare5.20261116.0-beta. Each number is the median of several runs.import('miniflare')import('@cloudflare/vite-plugin')import('miniflare')after Vite is loadedvite buildof a small SSR appSo about a quarter of a small production build is spent loading a local runtime that the build does not use. Tools that load the Vite config more than once pay it each time, and so does every test that runs a build in a subprocess.
A CPU profile of the Miniflare import splits like this:
src/config/schema.ts(16ms),src/plugins/index.ts(14ms),@cloudflare/config(13ms), thecore,sharedandagent-memoryplugins (10ms each),containers-shared(8ms).The Node compile cache does not help here, and neither does adding
"type": "commonjs"to Miniflare'spackage.json.What to change
Miniflareclass. Those code paths can useawait import('miniflare'). A build would then never load it.CoreHeaders,CorePathsandglobsToRegExps(the last one at build time). They are tiny, but today they are only available from the 6.2MB bundle. Something likeminiflare/sharedwould let the plugin import them statically without the rest.Personally, I think 1 and 2 together are the sweet spot. They are small, they do not change any public behavior, and they remove about 125ms from every build. 3 is worth doing later for dev startup.
Miniflare values are imported in 12 source files of the plugin today (
utils.ts,context.ts,cloudflare-environment.ts,websockets.ts,miniflare-options.ts,plugins/dev.ts,agent-hint.ts,trigger-handlers.ts,additional-modules.ts,tunnel.ts,shortcuts.ts,preview.ts), so the change is mostly moving imports around.I'm happy to send a PR for 1 and 2 if this sounds good.
All reactions