GLOBAL-MACROS Module

Here are some of the macro used to determine the execution environment, these macros are global variables, can be accessed directly.
When the project is built, these macros will be preprocessed and discard unreachable code based on the built platform, for example:

if (CC_DEBUG) {
    cc.log('debug');
}
else {
    cc.log('release');
}

After build will become:

cc.log('release');


To determine whether the script is running on the specified platform, you can use the following expression:

{
    "editor":  CC_EDITOR,
    "editor or preview":  CC_DEV,
    "editor or preview or build in debug mode":  CC_DEBUG,
    "web preview":  CC_PREVIEW && !CC_JSB,
    "simulator preview":  CC_PREVIEW && CC_JSB,
    "build in debug mode":  CC_BUILD && CC_DEBUG,
    "build in release mode":  CC_BUILD && !CC_DEBUG,
}

Index

Properties
  • CC_EDITOR Boolean Running in the editor.
  • CC_PREVIEW Boolean Preview in browser or simulator.
  • CC_DEV Boolean Running in the editor or preview.
  • CC_DEBUG Boolean Running in the editor or preview, or build in debug mode.
  • CC_BUILD Boolean Running in published project.
  • CC_JSB Boolean Running in native platform (mobile app, desktop app, or simulator).
  • CC_TEST Boolean Running in the engine's unit test.
  • CC_WECHATGAME Boolean Running in the Wechat's mini game.

Details

Properties

CC_EDITOR

Running in the editor.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:91
CC_PREVIEW

Preview in browser or simulator.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:94
CC_DEV

Running in the editor or preview.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:97
CC_DEBUG

Running in the editor or preview, or build in debug mode.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:100
CC_BUILD

Running in published project.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:103
CC_JSB

Running in native platform (mobile app, desktop app, or simulator).

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:106
CC_TEST

Running in the engine's unit test.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:109
CC_WECHATGAME

Running in the Wechat's mini game.

meta description
Type Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/index.js:112

results matching ""

    No results matching ""