Hi, I’m not sure if these are bugs or I’m doing something wrong, but I’m having the some issues when compiling a JavaScript project using the cocos console command. For ease of testingm I’m working with the default “empty/hello world” project that Cocos Code IDE creates when you select “File/New/Cocos JavaScript Project”:
Compiling without -m release in the command doesn’t do anything:
If I type cocos compile -p web all I get is “Running command: compile Building mode: debug” in the console, but no files are created. If I use cocos compile -p web -m release, I get feedback in the console and the files are created in the “publish” folder as expected and they work just fine.
Compiling for android does not create an “.apk” file (plus nothing happens without -m release):
If I type cocos compile -p android all I get is “Running command: compile Building mode: debug” in the console, but no files are created. If I use cocos compile -p android -m release, all I get is a “build.xml” file inside “publish/html5”, but I remember this command used to generate an “.apk” file that I could use in my Android emulator.
Build succeeds, but running fails if including underscore.js
I’ve been told that cocos2d-js should work alright with underscore.js, but if I include either the full underscore.js or minified underscore-min.js downloaded from the offficial site, after I run cocos compile -p web -m release I get a message of compilation succeeding, but when I try to run the sources I get “undefined is not a function” in the browser console in my “game.min.js”… This is really bothersome since I’m depending a lot on underscore’s functions for working with collections.
Can anyone give me a hand? (specially with problem 3).
EDIT / SOLUTION: all problems have been fixed as of Cocos2D-JS v3.0 final release.
It’s normal, the debug mode for web works with the sources files, so nothing new is created
release mode for android should create an apk, I’m not sure of this, I will check it out tomorrow
You may need to manually copy underscore.js into the publish folder, we haven’t check all dependencies in cocos console, in fact, it’s rely on your project.json’s configuration jsList, so if you include any external javascript file in index.html, please copy them manually into the publish folder, then it will work correctly
I’m, of course, putting "src/underscore.js" in jsList inside “project.json”. Then it does get compiled and in the minified code there’s no _.something to be found, so I can’t just re-add it to the compiled code…
After re-thinking this, I tried, instead of adding underscore.js to jsList, to add it as an external javascript file in index.html, and uncompiled it works, but after minifiying the _ get turned to something else either way… Is there a way to change the behaviour of the compiler so it would leave this kind of code untouched?
At this point, I thought the minified/compiled game was working, because if I go to the publish/html5 folder and run cocos run -p web the game works, but if I look at the sources with the browser’s developer tools I find out that it is actually running the code in the root folder of the project!
If I take the contents of the publish/html5 game and put the somewhere else (ie, in my web server) they still won’t work! D: (it says undefined is not a function for some line of the compiled code).
But I’ve realized something, now (after upgrading to v3 final) if I put "underscore.js" in project.json's jsList, I don’t need to do anything else for the compilation to work!
Has something changed in how the compiler works for Cocos2D-JS v3.0 Final?
I’m taking a look at game.min.js's code (re-formatted) and maybe I’m imagining things, but it doesn’t seem to be as obfuscated as it used to in previous releases.