Using version 2.4.6 through npm. I get this error:
bundle.js:23178 Uncaught ReferenceError: PIXI is not defined
Looks like PIXI not defined here in Phaser.js.
I also tried pulling from the master repo, npm install, grunt build, and just used require on the compiled phaser.js file but had the exact same problem.
Dupe of #2131.
I'm trying to have a quick look at making Phaser work with browserify and have all the dependencies for my projects in one place as it would work better with the rest of my toolchain but I think Rich and other have already intimated that it is not a trivial fix to support CJS modules. Not sure if Lazer is already set up to support CJS or not.
Just out of interest can you confirm that including Phaser like this works for you:
window.PIXI = require( 'phaser/build/custom/pixi' )
window.p2 = require( 'phaser/build/custom/p2' )
window.Phaser = require( 'phaser/build/custom/phaser-split' )
It's hardly using modules properly but might get you going in the short term.
It seems to be working just fine for me like this, next step will be adding aliases and stuff to make this a little easier.
I'm still going to poke around to see if it can be made a little nicer.
@mattstyles Yup seems to work great for me thanks!
This has been added to the README.
I'd say you could add a caveat in there about not fighting with CJS stuff and just include Phaser as a global, and use browserify-shim if you like to require( 'Phaser' ) in your code, but, honestly, the explanation is wordy enough. I'm not sure you should add another paragraph explaining how to use globals with browserify, thats up for users to work out from the browserify end.
Most helpful comment
I'm trying to have a quick look at making Phaser work with browserify and have all the dependencies for my projects in one place as it would work better with the rest of my toolchain but I think Rich and other have already intimated that it is not a trivial fix to support CJS modules. Not sure if Lazer is already set up to support CJS or not.
Just out of interest can you confirm that including Phaser like this works for you:
It's hardly using modules properly but might get you going in the short term.
It seems to be working just fine for me like this, next step will be adding aliases and stuff to make this a little easier.
I'm still going to poke around to see if it can be made a little nicer.