0.3.0 • Published 2 days ago

@hono/vite-cloudflare-pages v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

@hono/vite-cloudflare-pages

@hono/vite-cloudflare-pages is a Vite plugin to build your Hono application for Cloudflare Pages.

Usage

Installation

You can install vite and @hono/vite-cloudflare-pages via npm.

npm i -D vite @hono/vite-cloudflare-pages

Or you can install them with Bun.

bun add vite @hono/vite-cloudflare-pages

Settings

Add "type": "module" to your package.json. Then, create vite.config.ts and edit it.

import { defineConfig } from 'vite'
import pages from '@hono/vite-cloudflare-pages'

export default defineConfig({
  plugins: [pages()],
})

Build

Just run vite build.

npm exec vite build

Or

bunx --bun vite build

Deploy to Cloudflare Pages

Run the wrangler command.

wrangler pages deploy ./dist

Options

The options are below.

type CloudflarePagesOptions = {
  entry?: string | string[]
  outputDir?: string
  external?: string[]
  minify?: boolean
  emptyOutDir?: boolean
}

Default values:

export const defaultOptions = {
  entry: ['./src/index.tsx', './app/server.ts'],
  outputDir: './dist',
  external: [],
  minify: true,
  emptyOutDir: false,
}

Build a client

If you also want to build a client-side script, you can configure it as follows.

export default defineConfig(({ mode }) => {
  if (mode === 'client') {
    return {
      build: {
        rollupOptions: {
          input: './src/client.ts',
          output: {
            dir: './dist/static',
            entryFileNames: 'client.js',
          },
        },
        copyPublicDir: false,
      },
    }
  } else {
    return {
      plugins: [pages()],
    }
  }
})

The build command:

vite build --mode client && vite build

Authors

License

MIT

0.3.0

2 days ago

0.2.5

3 months ago

0.2.4

3 months ago

0.2.3

3 months ago

0.2.2

3 months ago

0.2.1

3 months ago

0.2.0

4 months ago

0.1.2

5 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.2

7 months ago

0.0.1

7 months ago