Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set multiple env variables for webpack?

Does anyone know how to provide multiple env vars to webpack? I was trying to run the following script without success.

"cross-env NODE_ENV=production DTM_ENV=staging webpack --config internals/webpack.prod.babel.js --color -p --progress"

On console.log(process.env) it only displays NODE_ENV: "production".

like image 735
dtalaba Avatar asked Feb 12 '18 13:02

dtalaba


1 Answers

Webpack doesn't have access to env variables after the build is done, so you need to expose those variables by adding this into Webpack config into plugins:

new webpack.DefinePlugin({
  'process.env': {
    NODE_ENV: JSON.stringify(process.env.NODE_ENV),
    DTM_ENV: JSON.stringify(process.env.DTM_ENV),
  }
})
like image 196
dtalaba Avatar answered Oct 06 '22 08:10

dtalaba