3

edit: I think I answered my own question here

I see many projects using cross-env with webpack but what for?

I see webpack 4 has --mode option which sets NODE_ENV for us but you can only choose 3 values (production,development,none so this is pretty much a standard now): https://webpack.js.org/configuration/mode/

In webpack >=3 there is --env command-line option which basically allows you to set process.env.{some property}

So we have 4 ways now to manage environment variables... Can you explain why is it so confusing?

  • webpack --env.NODE_ENV=local --env.production (v3 official example... NODE_ENV won't be set to production)
  • webpack --env.NODE_ENV=development
  • cross-env NODE_ENV=development webpack
  • webpack --mode=development

Related question: What is the difference between webpack --env.production and --mode="production"

More people are confused: https://www.jonathancreamer.com/webpack-production-environment-is-not-the-node_env-or-babel_env-environment-variable/

If I understand correctly in v4 --mode is the right standard way to set "development"/"production" so I will stick to that.

Konrad
  • 6,385
  • 12
  • 53
  • 96

0 Answers0