vite-plugin-cloudflare-workers-env-shims
v0.1.3
Published
A Vite plugin that provides shims for Cloudflare Workers environment variables.
Readme
vite-plugin-cloudflare-workers-env-shims
Vite plugin to add Cloudflare Workers environment shims.
Why?
If you are using vanilla Vite, you can use @cloudflare/vite-plugin. However if you use some frameworks including nitro, this plugin does not work. It is because there is some layer between Vite environment API and Vite plugin API.
This plugin enables to access to Cloudflare Workers environment API in dev mode in ergonomic way.
I created this because I have some troubles to use @cloudflare/vite-plugin in my Tanstack Start project.
Installation
npm install vite-plugin-cloudflare-workers-env-shims --save-devUsage
vite.config.ts
import { defineConfig } from 'vite'
import cloudflareWorkersEnvShims from 'vite-plugin-cloudflare-workers-env-shims'
export default defineConfig({
plugins: [
cloudflareWorkersEnvShims(),
],
})That's it! You can use Cloudflare Workers environment API in your code.
import { env } from 'cloudflare:workers'
// example
env.MY_KV.get('key').then((value) => {
console.log(value)
})