How to set multiple env variables using cross-env?

落花浮王杯 提交于 2020-05-23 08:32:12

问题


Does anyone know how to set multiple env vars using cross-env ? I was trying running 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".


回答1:


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),
  }
})


来源:https://stackoverflow.com/questions/48748054/how-to-set-multiple-env-variables-using-cross-env

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!