as the title said,i want to compress cocos2d-js framework into one file like cocos2d-htm5-2.2.2 SingleEngineFile.It is good to have a tutorial.
I found a Chinese document.
Address:
http://bbs.html5china.com/thread-1231-1-1.html
I don’t know, Can document help you?..
Hi, @ying1248
For single engine file, we will release an online engine builder page today to help you download it. Otherwise, you can go to cocos2d-js/frameworks/cocos2d-html5/tools
and run ant compile
to compile a full feature single engine file to cocos2d-js/frameworks/cocos2d-html5/lib
If you want to generate a single file with the engine and your own game js files together (only in this way you can use closure compiler advanced mode),
Sorry I just found that we don’t compiler tools in created projects, it will be added in beta.
You need to go to folder cocos2d-js/frameworks/cocos2d-html5/tools
copy build.xml
and compiler
folder to your project folder, then you need to modify the build.xml
to make sure the path to engine, the output path, the closure compiler path is correct. Then add your own js files into the source list. Then you can run ant compile
to compile the engine and your game into one compressed file.
Sorry I was mistaken about the compression with engine and game js files together.
We do already support it. You don’t need to do all the craps I mentioned, all you need is to run this command under your project folder.
cocos compile -p web -m release
Then you will find your published web project in publish/html5/
, where game.min.js is the single js file for your game.
@pandamicro I want to get var form a JSON file{“x”:1} ,and use the andvance mode.
a[“x”] is OK . Can I use the mode a.x,how to solve it?
Google closure have a syntax for variable which shouldn’t be compressed
Try this out:
/** @expose */
a.x;
@pandamicro 用cocos compile -p web -m release发布出来的是一个打包的js文件 但是用cocos compile -p android -m release发布出来的apk包里的代码却不是一个js文件,而是多个! 我看别人的源码里是一个jsc文件呢 请问这个是怎么回事? 求教程
Hi,
You can use another command for jsc file
cocos jscompile -s src -d src -c -j compiler_config_sample.json
While -s
means the scripts source directory, -d
means the output path, -c
means compress all scripts file into one file
-j compiler_config_sample.json
is also very important, you need to list all your script files in order into a json configuration file, so that the tool will know how they are related.
The example of this file can be found in cocos2d-js/tools/cocos2d-console/plugins/plugin_jscompile/bin/
Here is a simple example:
{
"pre_order":
[
"app.js",
"resource.js"
],
"post_order":
[
],
"skip":
[
],
"closure_params": ""
}