- Jenkins中shell脚本中暴露变量,暂定本地、测试、生产环境环境,有需要可添加
export RUNTIME_ENV=local/testing/release
- 在webpack插件配置中增加配置,注意使用JSON.stringify()
plugins: [
...,
new webpack.DefinePlugin({
'process.env': {
RUNTIME_ENV: JSON.stringify(process.env.RUNTIME_ENV || 'local'),
}
})
]
3.在你的js中使用
const RUNTIME_ENV = process.env.RUNTIME_ENV;