vite-plugins icon indicating copy to clipboard operation
vite-plugins copied to clipboard

Cloudflare Dev Server Plugins Hangs Build.

Open KevinEdry opened this issue 4 months ago • 0 comments

I have this config:

import { defineConfig } from 'vite'
import devServer from '@hono/vite-dev-server'
import build from '@hono/vite-build/cloudflare-workers'
import cloudflareAdapter from '@hono/vite-dev-server/cloudflare'
import tsconfigPaths from 'vite-tsconfig-paths'
import tailwindcss from '@tailwindcss/vite'

const entry = './src/index.tsx'
const cloudflareEnvironment = 'development'

export default defineConfig({
  assetsInclude: ['**/*.md'],
  plugins: [
    tailwindcss(),
    tsconfigPaths({
      root: '.'
    }),
    devServer({
      entry,
      adapter: cloudflareAdapter({
        proxy: { environment: cloudflareEnvironment }
      })
    }),
    build({ entry }) as never
  ],
  server: {
    cors: false
  }
})

When I run vite dev everything works, but when I run vite build the build hangs after it was done building. I narrowed it down to the cloudflareAdapter. If I pass the adapter directly without invoking the function, it exits the terminal when the build ends, but if I'm invoking the function to add the environment, the build hangs.

A workaround is to wrap the dev server in the serve command like so:

...(command === 'serve'
        ? [
            devServer({
              entry,
              adapter: cloudflareAdapter({
                proxy: { environment: cloudflareEnvironment }
              })
            })
          ]
        : []),

but I am sure this isn't sustainable.

KevinEdry avatar Aug 20 '25 03:08 KevinEdry