1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCode > Remote Containers > Reactの環境を作って、create-react-ap

Last updated at Posted at 2020-10-24

環境

Mac:Catalina
docker: 19.03.13
docker desktop for mac
Dockerはインストール済みとする。

環境準備

拡張機能である、Remote-Containersを入れる

スクリーンショット 2020-10-24 18.44.09.png

VSCodeを起動

適当な加フォルダでVSCodeを開きます(中身はからっぽでOK)

スクリーンショット 2020-10-24 18.35.01.png

開発コンテナ設定ファイルの作成

表示 > コマンドパレットを開く

Remote-Containers: Addまで打ち込んだら表示される、Remote-Containers: Add Development Container Configuration Files... を選択します。

スクリーンショット 2020-10-24 18.46.13.png

Show All Definitions...を選択します。

スクリーンショット 2020-10-24 18.48.07.png

検索BOXにnode と入力し、Node.js & Typescriptを選択します。
スクリーンショット 2020-10-24 18.50.28.png

バージョンは現時点最新の14を選択しときます
スクリーンショット 2020-10-24 18.53.49.png

これで設定ファイルが追加されました。

スクリーンショット 2020-10-24 18.54.20.png

React設定の追加 

Dockerfile

Dockerfileの17行目あたりにcreate-react-appのインストールを追加する

Dockerfile
# [Optional] Uncomment if you want to install more global node packages
# RUN sudo -u node npm install -g <your-package-list -here>
RUN sudo -u node npm install -g create-react-app

devcontainer.json

ポートフォワードの設定を行う。
23行目あたりのポートフォワードのコメントを外して3000と入力する。

devcontainer.json
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000],

Dockerの有効化

左下のアイコンをクリックし、
スクリーンショット 2020-10-24 19.03.49.png

コマンドパレットに表示されたContainers:Rebuild and Reopen in Containerを選択する。

スクリーンショット 2020-10-24 19.02.12.png

react app の作成と実行

作成

ターミナルにて以下を打ち込む

npx create-react-app my-app

スクリーンショット 2020-10-24 19.13.09.png

しばらく待つとreact appの雛形が作成される。
(初回はかなり待たされる)

スクリーンショット 2020-10-24 19.16.36.png

Happy hacking!が表示されたら完了

スクリーンショット 2020-10-24 19.19.43.png

実行

環境作成が完了したら、ターミナルにて以下を打ち込む

cd my-app
npm start

しばらく待つと起動します。

スクリーンショット 2020-10-24 19.22.49.png

ブラウザにて http://localhost:3000 にアクセス!
以下の画面が表示されればOK
スクリーンショット 2020-10-24 19.15.02.png

Happy hacking!

おまけ

Terminalにwarning: setlocale: LC_CTYPE: cannot change locale (ja_JP.UTF-8)と表示されるときは

スクリーンショット 2020-10-24 19.32.24.png

Dockerfileに以下を追加することで解決します

Dockerfile
RUN localedef -f UTF-8 -i ja_JP ja_JP.UTF-8

参考

How to use Visual Studio Code Remote Containers to develop Microsoft Teams apps · Garry Trinder

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?