diff --git a/packages/taro-cli/templates/default/src/index.html b/packages/taro-cli/templates/default/src/index.html index 826f423513e9..f72013ec16cb 100644 --- a/packages/taro-cli/templates/default/src/index.html +++ b/packages/taro-cli/templates/default/src/index.html @@ -10,7 +10,7 @@ diff --git a/packages/taro/src/env.js b/packages/taro/src/env.js index a8dc4ae79e40..84f9ce68c63b 100644 --- a/packages/taro/src/env.js +++ b/packages/taro/src/env.js @@ -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'