HonoH
Hono5mo ago
DangerZone

How to connect Vite, Hono and Cloudflare Workers?

I am trying to connect Hono with Vite on Cloudflare Workers, everything works, but the wrangler config. for some reason even with the adapter, the
wrangler.toml
doesn't get picked up and it fails to load environment variables.

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

export default defineConfig({
  assetsInclude: ['**/*.md'],
  plugins: [
    tsconfigPaths({
      root: '.'
    }),
    cloudflare(),
    devServer({
      entry: './src/index.tsx',
      adapter: cloudflareAdapter
    }),
    build({
      entry: './src/index.tsx',
      output: 'index.js',
      outputDir: './dist',
      external: [],
      minify: true,
      emptyOutDir: false,
      staticPaths: ['./public'],
      preset: 'hono'
    }) as never
  ],
  server: {
    cors: false
  }
})
Was this page helpful?