From d6f15a3e77ff183fc54d676153a7b14cb859aaca Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 17 Apr 2018 21:20:06 +0800 Subject: [PATCH 1/2] Support build native with native renderer option --- cocos2d/core/renderer/index.js | 2 +- gulp/tasks/engine.js | 16 ++++++++++------ gulp/util/utils.js | 2 +- jsb/index.js | 7 +++++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cocos2d/core/renderer/index.js b/cocos2d/core/renderer/index.js index 0252800d8d..da436ae34d 100644 --- a/cocos2d/core/renderer/index.js +++ b/cocos2d/core/renderer/index.js @@ -66,7 +66,7 @@ module.exports = { this.Texture2D = renderEngine.Texture2D; this.canvas = canvas; - if (CC_JSB) { + if (CC_JSB && CC_NATIVERENDERER) { // native codes will create an instance of Device, so just use the global instance. this.device = window.device; } diff --git a/gulp/tasks/engine.js b/gulp/tasks/engine.js index dbf5345cbe..1ffc28caab 100644 --- a/gulp/tasks/engine.js +++ b/gulp/tasks/engine.js @@ -213,9 +213,11 @@ exports.buildJsb = function (sourceFile, outputFile, excludes, opt_macroFlags, c var outFile = Path.basename(outputFile); var outDir = Path.dirname(outputFile); - var bundler = createBundler(sourceFile, { - aliasifyConfig: aliasifyConfig - }); + var opts = {}; + if (opt_macroFlags.nativeRenderer) { + opts.aliasifyConfig = aliasifyConfig; + } + var bundler = createBundler(sourceFile, opts); excludes = excludes.concat(jsbSkipModules); excludes.forEach(function (module) { bundler.ignore(require.resolve(module)); @@ -245,9 +247,11 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, opt_macroFlags var outFile = Path.basename(outputFile); var outDir = Path.dirname(outputFile); - var bundler = createBundler(sourceFile, { - aliasifyConfig: aliasifyConfig - }); + var opts = {}; + if (opt_macroFlags.nativeRenderer) { + opts.aliasifyConfig = aliasifyConfig; + } + var bundler = createBundler(sourceFile, opts); excludes = excludes.concat(jsbSkipModules); excludes.forEach(function (module) { bundler.ignore(require.resolve(module)); diff --git a/gulp/util/utils.js b/gulp/util/utils.js index 45774f5c61..cbbfef7622 100644 --- a/gulp/util/utils.js +++ b/gulp/util/utils.js @@ -1,6 +1,6 @@ const PLATFORM_MACROS = ['CC_EDITOR', 'CC_PREVIEW', 'CC_BUILD', 'CC_TEST']; -const FLAGS = ['jsb', 'wechatgame', 'qqplay', 'debug']; +const FLAGS = ['jsb', 'wechatgame', 'qqplay', 'debug', 'nativeRenderer']; // generate macros for uglify's global_defs // available platforms: 'editor' | 'preview' | 'build' | 'test' diff --git a/jsb/index.js b/jsb/index.js index b1c7f029ed..61e8012370 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -22,8 +22,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -require('./gfx'); -require('./renderer'); + +if (CC_NATIVERENDERER) { + require('./gfx'); + require('./renderer'); +} require('../index') require('./jsb-audio') require('./jsb-loader') From d2ad2ffcde78b16fa6d61dda16167a50f1df5c51 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 19 Apr 2018 10:35:43 +0800 Subject: [PATCH 2/2] Fix opt_macroFlags is null issue in gulp task --- gulp/tasks/engine.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gulp/tasks/engine.js b/gulp/tasks/engine.js index 1ffc28caab..17e46fc088 100644 --- a/gulp/tasks/engine.js +++ b/gulp/tasks/engine.js @@ -214,7 +214,7 @@ exports.buildJsb = function (sourceFile, outputFile, excludes, opt_macroFlags, c var outDir = Path.dirname(outputFile); var opts = {}; - if (opt_macroFlags.nativeRenderer) { + if (opt_macroFlags && opt_macroFlags.nativeRenderer) { opts.aliasifyConfig = aliasifyConfig; } var bundler = createBundler(sourceFile, opts); @@ -248,7 +248,7 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, opt_macroFlags var outDir = Path.dirname(outputFile); var opts = {}; - if (opt_macroFlags.nativeRenderer) { + if (opt_macroFlags && opt_macroFlags.nativeRenderer) { opts.aliasifyConfig = aliasifyConfig; } var bundler = createBundler(sourceFile, opts);