37
25

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.

Laravelで環境変数をJavascriptで使う

Last updated at Posted at 2017-11-07

JSファイルで使いたい環境変数がAPP_ENVだった場合。
.envファイルにMIX_プレフィックスを付けた環境変数を記述する。

#.envファイル
MIX_APP_ENV=local

JSファイル内でprocess.envオブジェクトを使って以下のように記述出来る

//index.js
if(process.env.MIX_APP_ENV === 'local'){
    console.log('ローカル環境');
}

参考
https://readouble.com/laravel/5.4/ja/mix.html

環境によってJSの記述を変える必要が出てきてしまって困っていたので助かった。
以上。

37
25
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
37
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?