Closed7

bun + cloudflare workers, deploy 手順

knaka Tech-Blogknaka Tech-Blog

mkdir projectName
cd projectName

bun init

bun --help


npm add

bun add -d @cloudflare/workers-types wrangler

bun 起動、ためし

bun run index.ts
knaka Tech-Blogknaka Tech-Blog

index.ts 修正

  • 今回は、フレームワークつかいません
index.ts
export interface Env {
}

export default {
	async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
		return new Response('Hello World-222!');
	},
};


  • package.json, 下記追加
  "scripts": {
    "start": "wrangler dev index.ts",
    "deploy": "wrangler deploy --minify index.ts"
  },
knaka Tech-Blogknaka Tech-Blog

wrangler.toml 参考

name = "bun_2test"
compatibility_date = "2023-09-01"

[vars]
#MY_VARIABLE = "production_value"

bun run start

dev-server , start

knaka Tech-Blogknaka Tech-Blog
  • package.json
{
  "name": "bun_2test",
  "module": "index.ts",
  "type": "module",
  "scripts": {
    "start": "wrangler dev index.ts",
    "deploy": "wrangler deploy --minify index.ts"
  },
  "devDependencies": {
    "@cloudflare/workers-types": "^4.20230914.0",
    "bun-types": "latest",
    "wrangler": "^3.8.0"
  },
  "peerDependencies": {
    "typescript": "^5.0.0"
  }
}
このスクラップは2023/09/19にクローズされました