Skip to content

Cloudflare Dev Server Plugins Hangs Build. #287

@KevinEdry

Description

@KevinEdry

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions