23
14

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 5 years have passed since last update.

create-react-appで環境変数を.envで設定する

Posted at

create-react-appでdotenv的に環境変数を使いたいとき
設定方法が特殊だったのでメモしておく

環境

node: 8.11.2
create-react-app: 1.1.4

使い方

環境変数は.envに書いておくと特に設定しなくても読み込んでくれる
ただし、変数名の前にREACT_APP_をつけておく必要がある

設定ファイル

.env
REACT_APP_APP_ID="xxxxx"

読み込む

api.js
let appId = process.env.REACT_APP_APP_ID

参考

23
14
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
23
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?