Modules

The engine expose functional interfaces to developers via modules, which exist as ECMAScript modules.

Note: from v3.0, it is strongly recommended not to use the global variable cc to access engine modules or classes.

Engine Modules

Function

The module 'cc' provides access to all engine functions. The contents of module 'cc' are dynamic and are related to the Feature Cropping setting in Project Setting.

Engine Log Output

Example:

  1. import { log } from 'cc';
  2. log('Hello world!');

Build-Time Constants

The engine module 'cc/env' exposes a number of build-time constants that represent the execution environment, debug level, or platform identifier, etc.

As these constants are declared with const, they provide good opportunities for code optimization.

Execution Environment

Name (all of type boolean)Description
BUILDWhether it is running in the post-build environment
PREVIEWWhether it is running in the preview environment
EDITORWhether it running in the editor environment

Debug Level

Name (all of type boolean)Description
DEBUGWhether it is in debug mode. Only false if the debug option is unchecked at build time, but true in all other cases.
DEVEquivalent to DEBUG/EDITOR/PREVIEW

Platform Identifier

The constants in the following table indicate whether the application is running on a particular or a class of platforms, and are all of type boolean.

NamePlatformMINIGAMERUNTIME_BASEDSUPPORT_JIT
HTML5Web
NATIVENative Platforms
ALIPAYAlipay Mini Game✔️✔️
BAIDUBaidu Mini Game✔️✔️
BYTEDANCEByteDance Mini Game✔️✔️
WECHATWeChat Mini Gamee✔️✔️
XIAOMIXiaomi Quick Game✔️✔️
COCOSPLAYCocos Play✔️✔️
HUAWEIHuawei Quick Game✔️✔️
OPPOOPPO Mini Game✔️✔️
VIVOvivo Mini Game✔️✔️

Output in Debug Mode

Examples are as follows:

  1. import { log } from 'cc';
  2. import { DEV } from 'cc/env';
  3. if (DEV) {
  4. log('I am in development mode!');
  5. }