Plugin developers: please test with the minifier

0 favourites
From the Asset Store
Soldier Test
$9.99 USD
A Construct version 2 & 3 "Stand-alone" RPG game with "In-Game Module" (IGM) integration.
  • Hi plugin developers,

    Just a heads up - we're getting bug reports that projects don't work after exporting with minifying enabled. I'm pretty sure this is because of third party plugins.

    The minifier renames object properties. If you mix object.prop and object["prop"] syntax your plugin will probably break the project on export. From the SDK documentation:

    hen exporting, Construct 2 gives the user the option to 'Minify script'. This runs the common and runtime scripts through Google Closure Compiler's ADVANCED_OPTIMIZATIONS mode. This imposes some limitations on what scripts can do. You must obey these limitations when writing your plugins, otherwise your plugin will be broken on export. More details can be found here (http://code.google.com/closure/compiler/docs/api-tutorial3.html).

    The main thing is to always use dot syntax (Object.property) rather than bracket syntax (Object["property"]). All properties using dot syntax are changed by Closure Compiler, but none of the properties in bracket syntax are changed. Therefore, if you use Object.property in one place and Object["property"] in another to access the same property, the plugin will be broken on export. You may still use bracket syntax (e.g. for a dictionary of user-inputted strings) - just be aware of how Closure Compiler will transform the code.

    Remember the edittime scripts are not passed through Google Closure Compiler, so you can write them how you like.

    Please double check all your plugins correctly minify on export! And don't forget to read the documentation! <img src="smileys/smiley1.gif" border="0" align="middle">

  • Thanks for the notification.

  • Perhaps having a plugin "lint" page that does what the minified would do and highlight potential problems might be helpful? Folks might paste their plugin code and run "lint" and it highlights parts of the code that could be problems. Just my 2 cents.

  • Looks like we have to avoid using {"propertyname":value} pairs as well.

    For example, this doesn't work:

    var test = {"count":0, "text" : "Some text"}

    Instead, use this:

    var test = {};
    test.count = 0;
    test.text = "Some text";
  • Mipey, doing

    var test = {"count":0, "text" : "Some text"}

    should be fine, so long as you access it with

    test["count"] = ...;
    test["text"] = ...'

    The minifier works by mangling all .property accesses, but never changes anything "in quotes". So you only break things by mixing and matching.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Good to know, thanks!

  • You guys are awesome

    understanding all codes...

    im so noob in front of you guys

    (i just started to learn c++ and im twelve)

  • My plugin makes heavy use of an external script... lots of Playtomic.Leaderboards.Save(data), Playtomic.Data.Views, etcetcetc

    This caused problems with the minifier and I ended up having to change everything to Playtomic["Leaderboards"]["Save"] and so on.

    So... it runs fine now, but it just looks a little strange to me. Did I do it right?

  • Yes, that looks right, but the 'Playtomic' variable can be renamed by the minifier too. It needs to be accessed by [""] syntax as well. The best thing to do is a global variable within the anonymous function for the plugin code, e.g.

    var myPlaytomic = window["Playtomic"];

    The external script has to have finished loading before this will work! This then always refers to the global variable by that name. Then, use

    myPlaytomic["Leaderboards"]["Save"]

    and so on. The syntax isn't very pretty, but it's really important to stick with it for the minifier to work.

  • Hi Ashley,

    Could it possible to mark a non-minify code area?

    I know the constrain of minify. The minify not only change the variable name, but also 'compile' the code. The behavior before minify/after minify 'might be' different.

    (Does physical behavior have this problem before?)

  • rexrainbow, the minifier doesn't support non-minify sections. Besides, as long as you write the code properly to the conditions the minifier requires, it does not change the functionality at all.

  • Thanks for the feedback, I'll push out a fix with it. Strange it never changed playtomic in all my testing, now that you mention it.

    Just curious, is the performance of [""] the same as directly referencing? I was under the general impression that looking up an object according to a string is a little slower than accessing it directly. But maybe it's different in js?

  • [""] is actually translated to . by the minifier, so it doesn't have any performance impact. In other words object.mySuperProperty will be minified to something like m.pX, but object["mySuperProperty"] will be minified to m.mySuperProperty (so it keeps the name but changes the syntax).

    I just realised if 'Playtomic' is defined by an external script, you don't need to do what I said, because it's defined in another script that is not minified :)

  • Super, thanks!

  • I am having issues in reading objects local variable in plugins.

    even without the minifier, parsing a variable name in plugin to fetch the value is not working.

    is the exporter braking it? because it is working fine in browser.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)