Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: 优化环境变量的获取 #4669

Merged
merged 4 commits into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/taro/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,41 @@ export const ENV_TYPE = {
JD: 'JD'
}

let _env = null

// 一个taro项目肯定运行同样的环境
export function getEnv () {
if (_env) return _env
if (typeof jd !== 'undefined' && jd.getSystemInfo) {
_env = ENV_TYPE.JD
return ENV_TYPE.JD
}
if (typeof qq !== 'undefined' && qq.getSystemInfo) {
_env = ENV_TYPE.QQ
return ENV_TYPE.QQ
}
if (typeof tt !== 'undefined' && tt.getSystemInfo) {
_env = ENV_TYPE.TT
return ENV_TYPE.TT
}
if (typeof wx !== 'undefined' && wx.getSystemInfo) {
_env = ENV_TYPE.WEAPP
return ENV_TYPE.WEAPP
}
if (typeof swan !== 'undefined' && swan.getSystemInfo) {
_env = ENV_TYPE.SWAN
return ENV_TYPE.SWAN
}
if (typeof my !== 'undefined' && my.getSystemInfo) {
_env = ENV_TYPE.ALIPAY
return ENV_TYPE.ALIPAY
}
if (typeof global !== 'undefined' && global.__fbGenNativeModule) {
_env = ENV_TYPE.RN
return ENV_TYPE.RN
}
if (typeof window !== 'undefined') {
_env = ENV_TYPE.WEB
return ENV_TYPE.WEB
}
return 'Unknown environment'
Expand Down