LoginSignup
1
1

More than 1 year has passed since last update.

VSCodeでDenoをコーディングする際の準備

Last updated at Posted at 2020-05-25

巷で話題のDenoはじめました。
image.png
↑かわいい


うちのエンジニアの若い子たちも気軽に始められるように、少しずつDenoなコンテンツも書いていけたらなと思っています。まずはプログラムを書くための環境からということでVSCodeでDenoを書くための準備をしましょう。

サンプルとしてGoogleにアクセスするコードを書いてみました。

sample1.ts
import {Status} from 'https://deno.land/std/http/http_status.ts';

const result = await fetch("https://google.com");
if ( result.status === Status.OK ){
  console.log("OKですよ");
}else{
  console.log(`なんかエラーですよ:${result.status}`);
}

VSCodeを立ち上げておもむろにTypeScriptを書いていくと、エラーとなります。
image.png

DenoのランタイムにはTypeScriptのトランスパイラが含まれるため、TypeScriptで記述することはできますが、VSCodeはDenoを知らないためエディタの支援機能を得ることができません。

試しに

deno run --allow-net sample1.ts

とコマンドラインから起動すれば普通に動きます。

$ deno run --allow-net sample1.ts
Compile sample1.ts
OKですよ

VSCodeにjustjavac.vscode-denoプラグインを追加

VSCodeの左側Extensionsボタンを押してSearch Extensions in Marketplaceテキストボックスにdenoと入力して検索すると該当のプラグインが見つかります。
image.png

該当のプラグインを無効にする場合はコマンドパレットに

Disable Deno

逆に有効にする場合は

Enable Deno

と入力します。
既存のプロジェクトにも影響を及ぼしますので、DenoのプロジェクトはEnable Denoしておいて他のプロジェクトはDisable Denoしておいてくださいね。

では、一緒にDeno楽しみましょう。広がると良いですね!

1
1
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
1
1