@hono/vite-netlify
is a Vite plugin to build your Hono application for Bun.
You can install vite
and @hono/vite-netlify
via npm.
npm i -D vite @hono/vite-netlify
Or you can install them with Bun.
bun add vite @hono/vite-netlify
Add "type": "module"
to your package.json
. Then, create vite.config.ts
and edit it.
import { defineConfig } from 'vite'
import pages from '@hono/vite-netlify/functions'
// or: import pages from '@hono/vite-netlify/edge-functions'
export default defineConfig({
plugins: [pages()],
})
Just run vite build
.
npm exec vite build
Or
bunx --bun vite build
Run the netlify
command.
netlify deploy --prod
The options are below.
type NetlifyOptions = {
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,
}
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
- Clément Songis https://github.com/chtibizoux
MIT