18
15

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.

Nuxt.jsで.envファイルを扱う@nuxtjs/dotenv

Last updated at Posted at 2019-07-25

@nuxtjs/dotenvを使います

.envファイル作成

下記コマンドでルート配下に.envを作成

touch .env

下記のように環境変数記述

.env.dev
API=http://localhost:8000/api/

nuxt.config.js設定

nuxt.config.js
require('dotenv').config();
const {API} = process.env;

export default {
  env: {
    API
  },
}

動作確認

/pages/index.vue
export default {
  created() {
    console.log(process.env.API)
  }
}
18
15
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
18
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?