Closed dgoemans closed 9 years ago
The minified p2.min.js increase in file size by 45% when doing this. Is there any other way of fixing it?
Have a look at the requireJsFix task. If you omit it when building (run grunt browserify concat uglify
), does it work better for you?
Ok, so I played around with this a bit more. Removing or changing the requireFix wasn't really enough, but it was enough to name the module.exports namespace - which seems like intended behaviour anyway right? The result.. same size library, and my phaser build is working :tada:
Side note though, if you are really want to drop the filesize, I'd suggest turning on the compression from Uglify. That should at least halve your library size. If i remember correctly from my JS13k entry, doing both a mangle and compress should get you down to about 25% of non-compress/mangled code. I took a quick stab at it, but there are some issues that it doesn't like, probably some minor things that a lint tool would pick up such as missing ; at the end of a line or accessing properties as strings.
What, how does that even work, it's just a local var? Is there a simpler way of testing that it works?
Will check out that compression thing, sounds promising!
From what I understand is that it creates a local variable in that scope and assigns it to the entire namespace that you've setup in the module.exports. Then browserify generates that module.exports that overwrites the above variable but somehow when using requirejs, it instead breaks what browserify adds, and so it'll now use the original var. Not a fun one to understand :confused:
The simplest way i currently have of testing is by taking a non-minified build of p2, shoving it into Phaser, building that, and running an example game. I have an example game here which i'm starting as a article series on game dev: https://github.com/dgoemans/awesomegame I just pushed the version that includes the p2 changes I did.
Thanks for the code change, works great.
@dgoemans I take it insertGlobals: true
is not needed then? Still haven't tested this for myself, sorry.
Nope, not needed anymore, so the size is back down to what it should be.
Okay, cool! Thanks.
Fixed compatibility with phaser and requirejs. Seems that phaser uses p2 globally, and when included with requirejs, it fails to pickup the global p2.