Custom build template for FB instant games per project

Custom build template for FB instant games per project
0.0 0


I would like to have a custom build template for my FB instant games projects, preferably different for each of the projects I have.

According to the documentation about custom templates it seems easy (see here. However, after searching in CocosCreator/resources/static/build-templates there is no fb target.

I tried creating my custom build template folder for instant games anyway, however files are not being swapped.

After some more digging I found this documentation, where under Custom Instant Games paragraph you can find that you can change index.html file for a custom one under resources/static/fb-instant-games/.

Is it really the only existing solution, changing it globally? No possibility to have custom build template per each of my instant games projects?


We have a build script that takes care of that. CC supports only one template pr. build target so you have to overwrite it before compiling.

With the example below you can build and upload to facebook with
sh "some comment"

#!/bin/bash -i
if [ -z "$COMMENT" ]; then COMMENT="Staging"; fi

BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"


echo '***************************'
echo '**                       **'
echo '**     COPY TEMPLATE     **'
echo '**                       **'
echo '***************************'
cd ..
rm -rf build-templates
mkdir build-templates
cp -r build-scripts/templates/build-templates-facebook/web-mobile build-templates/web-mobile

echo '***************************'
echo '**                       **'
echo '**        STAGING        **'
echo '**                       **'
echo '***************************'

echo 'APP ID: ' $APPID

echo '***************************'
echo '**                       **'
echo '**     BUILD PROJECT     **'
echo '**                       **'
echo '***************************'

mkdir -p ../build
/Applications/ --path ../ --build "platform=web-mobile;buildPath=./build"
cd ../build/web-mobile/
rm -f ../build/ && zip -r ../  ./
echo '***************************'
echo '**                       **'
echo '**                       **'
echo '***************************'
curl -O -# -X POST$APPID/assets -F 'access_token='"$ACCESSTOKEN"'' -F 'type=BUNDLE' -F 'asset=@../' -F "comment=$COMMENT"

echo 'DONE!'


That is really nice workaround :wink:

However, now cocos supports custom build templates per build target per project, which doesn’t need overriding cocos templates, but use files located in PROJECT_PATH/build-templates/build-target, that is why I asked why there is no similar solution for Facebook Instant Games.

If cocos devs won’t add it we probably end up with such building and copying script as well.

Thanks for sharing.


Ooh. I didn’t know. Since when does it support that?


I’m not sure since when, because we started development with 1.8 version. Here is link to documentation.


As far as I can see this is just pr. target. In our case we would need two different web-mobile templates.


I found that it actually works, but the “fb-instant-games” template folder is in the wrong place in the Cocos Creator app package (on Mac). I moved that folder into the “Cocos Creator/Contents/Resources/static/build-templates” folder, and it worked as described in the documentation.

So, you can have a config per project, but the default Cocos distribution has it in the wrong place. Maybe they will fix that in the next patch. It’s a simple matter of moving one folder. :slight_smile:

UPDATE: Ah, poop. Looks like there’s still some issue in the engine because the main.js file has some syntax error (renderMode: <%=renderMode%>) preventing the app from starting. So close.

UPDATE2: In main.js, I changed the rendermode to 0 (which is supposed to let the engine decide), and my app started correctly. Not sure what the consequences of letting the engine choose are.

UPDATE3: I noticed some other “template” variables that are not being populated correctly in index.html, but they don’t seem to have a noticeable effect (not yet, anyway). The devs need to verify this feature and make sure it’s working 100%. I’m using Cocos Creator 1.9.0.