weex-env
v0.2.0
Published
weex environment detect
Downloads
11
Readme
Weex 运行环境检测
实时检测 Weex 的运行环境和版本,支持 1.0 和 2.0 以及降级后的场景。
注 Weex 1.0 和 2.0 不是真实版本号,用来代指两个架构差异较大的版本(1.0 已开源,2.0 开发中)。
安装使用
- 安装 npm 包:
npm i weex-env -S
- 使用:
import { isWeex, isWeexV2 } from 'weex-env'
if (isWeexV2) {
// some conditional code here
}
环境变量
isWeb
: 是否为浏览器运行环境。isWeex
: 是否为 Weex 的运行环境,包括 1.0、2.0,不包括降级。isWeexV1
: 是否为 Weex 1.0 的原生运行环境,不包括降级。isWeexV2
: 是否为 Weex 2.0 的原生运行环境,不包括降级。
在各环境中的值
| 变量 | 浏览器 | Weex1.0 原生容器 | Weex1.0 降级(H5) | Weex2.0 原生容器 | Weex2.0 降级(H5) | | --- | --- | --- | --- | --- | --- | | isWeb | ✅ | ❌ | ✅ | ❌ | ✅ | | isWeex | ❌ | ✅ | ❌ | ✅ | ❌ | | isWeexV1 | ❌ | ✅ | ❌ | ❌ | ❌ | | isWeexV2 | ❌ | ❌ | ❌ | ✅ | ❌ |