Jump to content

Custom Builds?


Recommended Posts

We've been using Phaser-CE and doing custom builds to exclude components that we don't use (such as physics engines that we don't use, etc). I've been looking over the docs and don't see a way to do that in Phaser 3. Am I missing something or is that indeed the case?

Link to comment
Share on other sites

You can do incredibly granular builds of Phaser 3! Literally chop out anything you don't use, right down to single Actions or File Type Loaders.

I'll write a proper tutorial on it for a Dev Log soon, but for now the key to it is using webpack to make a custom build by changing the contents of the entry point.

Webpack uses src/phaser.js as the entry point for the 'full' build, and src/phaser-core.js for the 'core' build.

If you look at these files you'll see they are basically a list of all the things to be included in a build, that is exposed under the Phaser namespace. If you look at the core file you'll see the GameObjects object breaks down into sections and that TileSprite and the Bitmap Text objects aren't in there for example.  You can also see it's got far less Loader File Types too. Basically, anything in this file is bundled in.

If you just link to a folder it'll take the index.js file from that folder and include everything in it:

Actions: require('./actions')

Here, every single Action will be included. But you could change it to this:

Actions: {
    GridAlign: require('./actions/GridAlign'),
    RandomLine: require('./actions/RandomLine'),
    Shuffle: require('./actions/Shuffle')

Now, only the 3 Actions listed will be included.

You don't have to worry about dependencies. For example, the Shuffle action requires the ArrayShuffle function from the utils/array folder, but it will be pulled in automatically because of the way webpack works. So think about the phaser.js file as being what you want Phaser to expose in its namespace. You could literally have nothing other than the 'Game' entry and that in itself will pull in everything it needs for a core, base Phaser to work. There won't be any Game Objects of course and no File Types for the Loader :) but it would still work. Perhaps if you were rendering a whole game using just the Graphics object then you could skip adding the Loader entirely!

That's the basic gist of it anyway. Clone the repo, create your own phaser.js entry point, put in it whatever you use and let webpack worry about the rest.

Link to comment
Share on other sites

  • rich pinned this topic
  • 4 weeks later...
  • samme unpinned this topic

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...