Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/node-libraries/vite-plugin-miniflare
Plug-in for running Vite development code on Workerd VM
https://github.com/node-libraries/vite-plugin-miniflare
Last synced: 2 months ago
JSON representation
Plug-in for running Vite development code on Workerd VM
- Host: GitHub
- URL: https://github.com/node-libraries/vite-plugin-miniflare
- Owner: node-libraries
- Created: 2024-10-25T02:09:29.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-10-27T07:04:34.000Z (3 months ago)
- Last Synced: 2024-10-27T15:11:04.785Z (3 months ago)
- Language: TypeScript
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```ts
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
```ts
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(
{await getCount()}
);
});export default app;
```