How to set multiple env variables for webpack?

前端 未结 1 1146
盖世英雄少女心
盖世英雄少女心 2021-01-12 06:47

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 DT         


        
相关标签:
1条回答
  • 2021-01-12 07:08

    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),
      }
    })
    
    0 讨论(0)
提交回复
热议问题