2
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.

webpack NODE_ENV でハマった話

Last updated at Posted at 2019-12-20

背景

NODE_ENVの値で分岐を行いたいと考えていました。
しかし、何を設定しても起動するとproductionとなる...

調査

調査用に、下記のようなコードを追加

console.log(`current env => ${process.env.NODE_ENV}`)

webpackしてみると出てきたコードは

console.log("current env => production")

まさかの変換されてしまってました。
どうやらwebpack.config.jsで指定したmodeの値が代入されてしまうようです。

解決策

optimization.nodeEnvfalseを設定する。

webpack.config.js
module.exports = {
  mode: 'production',
  // ここを追加
  optimization: {
    nodeEnv: false
  },
  // 省略
}
2
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
2
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?