Skip to content

node-libraries/vite-plugin-miniflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-miniflare

Sample code

https://github.com/SoraKumo001/hono-miniflare
https://github.com/SoraKumo001/remix-prisma-vite-miniflare

  • vite.config.ts

Using vite-plugin-miniflare

import { defineConfig } from "vite";
import { devServer } from "vite-plugin-miniflare";
export default defineConfig({
  // Only if the front module is required
  // build: {},

  plugins: [
    devServer({
      entry: "src/index.tsx",
      // Bundle all ENTRY modules.
      bundle: true,
      // Set to true for automatic reloading without HMR
      reload: true,
    }),
  ],
});
  • src/index.tsx

Making CacheAPI work on Vite

import { Hono } from "hono";

const app = new Hono();

const getCount = async () => {
  const cache = await caches.open("hono-ssr-react-miniflare");
  const url = new URL("/count", "http://localhost");
  const cachedResponse = await cache.match(url);
  const count = cachedResponse ? parseInt(await cachedResponse.text()) : 1;
  await cache.put(
    url,
    new Response((count + 1).toString(), {
      headers: {
        "Content-Type": "text/plain",
        "Cache-Control": "max-age=31536000",
      },
    })
  );
  return count;
};

app.get("*", async (c) => {
  return c.html(
    <html>
      <body>{await getCount()}</body>
    </html>
  );
});

export default app;

About

Plug-in for running Vite development code on Workerd VM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published