mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
1c737b91fd
* publish build-engine 4.3.5 * update build-engine deps * remove default-constants.ts ds remove de * delete consts.d.ts * support build-const workflow * remove EXPORT_TO_GLOBAL * update comment * fix interface-check * update comment
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
const _global = typeof window === 'undefined' ? global : window;
|
|
|
|
function defined (name: string) {
|
|
return typeof _global[name] === 'object';
|
|
}
|
|
|
|
function tryDefineGlobal (name: string, value: boolean): boolean {
|
|
if (typeof _global[name] === 'undefined') {
|
|
return (_global[name] = value);
|
|
} else {
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
return _global[name];
|
|
}
|
|
}
|
|
|
|
// No export to global required since we have already done here.
|
|
export const BUILD = tryDefineGlobal('CC_BUILD', false);
|
|
export const TEST = tryDefineGlobal('CC_TEST', true);
|
|
export const EDITOR = tryDefineGlobal('CC_EDITOR', false);
|
|
export const PREVIEW = tryDefineGlobal('CC_PREVIEW', !EDITOR);
|
|
export const DEV = tryDefineGlobal('CC_DEV', true); // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST
|
|
export const DEBUG = tryDefineGlobal('CC_DEBUG', true); // CC_DEV || Debug Build
|
|
export const JSB = tryDefineGlobal('CC_JSB', defined('jsb'));
|
|
export const NATIVE = JSB;
|
|
export const HTML5 = !(EDITOR && NATIVE);
|
|
// @ts-expect-error: 'wx' is wechat namespace.
|
|
export const WECHAT = tryDefineGlobal('CC_WECHAT', !!(defined('wx') && (wx.getSystemInfoSync || wx.getSharedCanvas)));
|
|
export const MINIGAME = tryDefineGlobal('CC_MINIGAME', false);
|
|
export const RUNTIME_BASED = tryDefineGlobal('CC_RUNTIME_BASED', false);
|
|
export const ALIPAY = tryDefineGlobal('CC_ALIPAY', false);
|
|
export const XIAOMI = tryDefineGlobal('CC_XIAOMI', false);
|
|
export const BYTEDANCE = tryDefineGlobal('CC_BYTEDANCE', false);
|
|
export const BAIDU = tryDefineGlobal('CC_BAIDU', false);
|
|
export const COCOSPLAY = tryDefineGlobal('CC_COCOSPLAY', false);
|
|
export const HUAWEI = tryDefineGlobal('CC_HUAWEI', false);
|
|
export const OPPO = tryDefineGlobal('CC_OPPO', false);
|
|
export const VIVO = tryDefineGlobal('CC_VIVO', false);
|
|
// @ts-expect-error: 'loadRuntime' exits only in runtime environment.
|
|
export const SUPPORT_JIT = tryDefineGlobal('CC_SUPPORT_JIT', (typeof loadRuntime === 'function'));
|
|
export const SERVER_MODE = false;
|