Bundling a Phaser project with Parcel
There is, however, one tiny caveat; loading an asset (e.g. an image) implies providing its relative path as a string, delegating the underlying logic to Phaser itself:
import Phaser from "phaser";
export default new Phaser.Class({
// ...
preload() {
this.load.image("tiles", "../../assets/map/spritesheet.png");
}
});
In the context of a built project, the above just might fail, since our PNG file will be out of reach from its scope. In the case of Parcel, the way to go is pretty straightforward, and consists of bundling these assets with the code and using its internal mechanism to get a proper reference to their actual location:
import Phaser from "phaser";
import tiles from "../../assets/map/spritesheet.png";
export default new Phaser.Class({
// ...
preload() {
this.load.image("tiles", tiles);
}
});
A similar solution is probably available with other bundlers. Finally, one might argue they would probably be better off loading those assets statically, but that seems to be a somewhat controversial topic with Parcel.