Cocos Creator and goog closure

Hi,

My project based on google closure (including deriving classes ecosystem and compiler) and I want to start develop on Cocos Creator as a game engine. But it looks as for now support of third party modules is limited. Do you have any plans in near updates to provide better support for goog closure library?

Thank you!

What’s the problem did you meet with closure library? Please refer to this document for details of third plugins: http://www.cocos.com/docs/creator/scripting/plugin-scripts.html

Hi!
Thank you for pointing me to this link! I have read English version but Chinese version has more info.
As I understand I need to merge all goog closure scripts into one large script. But another question how to use classes from it. Closure library has no module.exports for types. Also how I can control load priority of scripts. I need first to load closure after that load my project scripts. When I have added module.exports in base.js and then use const goog = require(“base”); goog.provide(“com.lib.classname”); in my script I receive that goog.provide not a function error in Creator console. When I looking project.dev.js I see that base.js included at the end of the file causing such error. Follow that I have two questions:

  1. Is there any way I can control load priority in Cocos Creator to load base.js and other closure dependencies first?
  2. How to use types from closure libs?

Thank you,
Nick

It should export some API like window.goog.math.clamp, see Closure Library Namespace

Closure have an official way to build it, see https://developers.google.com/closure/library/docs/closurebuilder

If you import a script as plugin, it will load before all other normal scirpts.

Hi, jare,

Thanks for fast reply!

I mean is there any way to control plugin loading in Cocos Creator. I read here http://www.cocos.com/docs/creator/scripting/plugin-scripts.html that only alphabetical order supported.

In development mode Google Closure using dependency writer for creating dependency.js that use for load scripts in right order to the dom. if loading to the dom not the case Google Closure provide the possibility to override CLOSURE_IMPORT_SCRIPT function to populate dependency manually and load it on own way.

It would be nice if Cocos Creator will provide option for control over plugins script loading.

Thank you!

Sorry no other kind of priority for now. In creator, the only way is combine your plugin scripts into one file. I think you should use https://developers.google.com/closure/library/docs/closurebuilder. But if Closure is still to complex to do so, you can just override the static/build-templates/*/*/index.html and load Closure in it.

Hi jare,

Thanks for reply! Merging closure library in development mode is uncomfortably.

In my case I use WebStorm for coding and Cocos Creator for UI creation, building project and JSB debugging. Each time before launch dependency writer script provided by closure executed to build right order for script loading. It would be great if Cocos Creator will provide in future possibility to control script loading. For example, this may be done by launching special js script which populate custom order of scripts loading on before build event. In this case it’s possible to use output script from tools like dependency writer provided by closure or put manual logic. Hope that my feedback will be helpful for Cocos Team.

Anyway thank you for your help!

Wish a nice day to you,
Nick