0
0

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.

Next.jsでdotenvを使う方法

Posted at

dotenv-webpackをインストールする

まずはNext.jsでdotenvを導入する上で必要なモジュールをインストールします。

npm i dotenv-webpack

next.config.jsにてdotenvの設定を行う

以下みたいな感じでOK。

next.config.js
require("dotenv").config();

const path = require("path");

const Dotenv = require("dotenv-webpack");

module.exports = {
  webpack: config => {
    config.plugins = config.plugins || [];

    config.plugins = [
      ...config.plugins,

      new Dotenv({
        path: path.join(__dirname, "env"),
        systemvars: true
      })
    ];

    return config;
  }
};

これで「process.env.」が使えるようになります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?