LoginSignup
0
0

More than 1 year has passed since last update.

denoの標準オプションでHotReloadする

Last updated at Posted at 2021-12-31

結論

deno run --watch=<FILES> server.ts

deno runする際に --watchオプションを追加する
※UNSTABLEなので注意してください。

環境

$ deno --version
deno 1.17.0 (release, x86_64-apple-darwin)
v8 9.7.106.15
typescript 4.5.2

手順

1. server.tsを作成

server.ts
import { serve } from "https://deno.land/std@0.119.0/http/server.ts";

serve(() => new Response("Hello Deno\n"));

2. --watchオプションをつけてサーバーを実行

deno run --allow-net --watch=./ ./server.ts

3. curlして結果をみる

$ curl localhost:8000
Hello Deno

4. server.tsを編集

server.ts
import { serve } from "https://deno.land/std@0.119.0/http/server.ts";

serve(() => new Response("Hello 🦕\n"));

5. curlして結果を見る

$ curl localhost:8000
Hello 🦕

これでHotReloadできました。

今回使ったソースを以下に置きます。

備考・感想

  • 今回使ったwatchオプションはdeno 1.17.0現在ではUNSTABLEなので、ご注意ください。
  • denonというHotRelaodツールもありましたが、筆者が使おうとしたタイミングでは、最新版のinstallができず、folk後修正されたものを使っていました笑
  • denoのエコシステムは活動が活発なので、楽しくwatchしていきたいですね〜

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0