Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hono/vite-dev-server

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hono/vite-dev-server

Vite dev-server plugin for Hono

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.7K
decreased by-84.76%
Maintainers
1
Weekly downloads
 
Created
Source

@hono/vite-dev-server

@hono/vite-dev-server is a Vite Plugin that provides a custom dev-server for fetch-based web applications like those using Hono. You can develop your application with Vite. It's fast.

Features

  • Support any fetch-based applications.
  • Hono applications run on.
  • Fast by Vite.
  • HMR.
  • Supporting Cloudflare Bindings.

Demo

https://github.com/honojs/vite-plugins/assets/10682/a93ee4c5-2e1a-4b17-8bb2-64f955f2f0b0

Supported applications

You can run any application on @hono/vite-dev-server that uses fetch and is built with Web Standard APIs. The minimal application is the following.

export default {
  fetch(_request: Request) {
    return new Response('Hello Vite!')
  },
}

This code can also run on Cloudflare Workers or Bun. And if you change the entry point, you can run on Deno, Vercel, Lagon, and other platforms.

Hono is designed for fetch-based application like this.

import { Hono } from 'hono'

const app = new Hono()

app.get('/', (c) => c.text('Hello Vite!'))

export default app

So, any Hono application will run on @hono/vite-dev-server.

Usage

Installation

You can install vite and @hono/vite-dev-server via npm.

npm i -D vite @hono/vite-dev-server

Settings

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

import { defineConfig } from 'vite'
import devServer from '@hono/vite-dev-server'

export default defineConfig({
  plugins: [
    devServer({
      entry: 'src/index.ts', // The file path of your application.
    }),
  ],
})

Development

Just run vite.

npm exec vite

Options

The options are below. WorkerOptions imported from miniflare are used for Cloudflare Bindings.

import type { WorkerOptions } from 'miniflare'

export type DevServerOptions = {
  entry?: string
  injectClientScript?: boolean
  cf?: Partial<
    Omit<
      WorkerOptions,
      'name' | 'script' | 'scriptPath' | 'modules' | 'modulesRoot' | 'modulesRules'
    >
  >
}

injectClientScript

If it's true and the response content-type is "HTML", inject the script that enables Hot-reload. default is true.

Cloudflare Bindings

You can use Cloudflare Bindings like variables, KV, D1, and others.

export default defineConfig({
  plugins: [
    devServer({
      entry: 'src/index.ts',
      cf: {
        bindings: {
          NAME: 'Hono',
        },
        kvNamespaces: ['MY_KV'],
      },
    }),
  ],
})

These Bindings are emulated by Miniflare in the local.

Notes

Depending on Miniflare

@hono/vite-dev-server depends on miniflare for certain platforms you may want to run on. For example, if you want to run your applications on Node.js, the miniflare is not needed. However, it's necessary for Cloudflare Workers/Pages, which are important platforms for Hono. And miniflare is needed just for development; it will not be bundled for production. So we allow including miniflare in @hono/vite-dev-server.

Authors

License

MIT

FAQs

Package last updated on 07 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc