New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't require Phaser in Electron #3598
Comments
I was afraid that would be the answer here. It seems that there are two things in that Webpack config that could be simplified and allowing to skip Webpack completely when using Electron. One is to allow requiring shader files. This could be done like this:
And the other thing would be to set Is there anything else preventing Phaser to run in Electron as is? |
As long as it doesn't break our build process I'll be happy to take a PR for this. |
I'll try, please be patient :) |
@photonstorm I've investigated the situation and it appears, that there are no shortcuts here and both
And then everywhere they are used of course we would need to have to import (require) them like you do already with other constants:
That would require around 20 files to be modified. Would you accept such PR, or you have a different idea how to approach this? |
The problem is, if you do that, both the Canvas and WebGL files will be included in to the bundle. That's why we use the webpack plugin to handle it, because they're parsed out at build time and only the relevant renderer (or both, depending on the config) is included. Swap them for normal consts and it'll always include them both :( |
That complicates things a bit. I'm not a Webpack user, but maybe that would just work in the Webpack config file:
I'll experiment with that and maybe more ideas will popup, will let you know. |
Possibly. Will test it now and see. |
Damn, sadly not. Swapping to use
Where-as if the plugin had run properly it would contain:
|
Looking at the DefinePlugin docs (https://webpack.js.org/plugins/define-plugin/) it looks like we could store the flags inside the node environment process instead, Not really sure if that makes it any easier for non-Webpack users though. |
Yeah that works: |
Yes, I believe it should work, that would of course require to define these environment variables before importing Phaser. I've also found another way from the DefinePlugin's documentation, by leveraging the
And it seems to work too, with code like this:
Of course that would require to prefix all I don't actually understand what the |
@photonstorm So, I can make a PR with |
I don't mind sticking the Doesn't get around the shader raw-loader use though. |
For shader loading we can leverage the code from my earlier comment and it will work fine. This needs to be put in somewhere at the beginning of the Phaser's code, probably in
|
Where does this part go?
As it can't go in the Phaser source. |
It would need to be in Phaser's source, somewhere at the beginning, before first requires. It could be completely disabled when building with Webpack using the same trick with the DefinePlugin (it would be always stripped with Webpack). |
Ahh ok - it'd still try and bundle in the whole of |
Can |
@photonstorm It's done, that's awesome, thank you very much! |
I'm going to have to undo the |
Ok all sorted :) 3.7.1 includes a new way of handling shaders, so Electron should work fine now. |
I was bit worried for a moment, but great you've managed this. Desktop games in Phaser, yay! :) |
Can you recommend the best way to scaffold out a Phaser + Electron project? |
I'm not being able to require Phaser in a desktop application running in Electron v1.8.4.
According to the readme file, one's could install Phaser 3 using NPM like this:
After that, when running Electron and trying to require Phaser, an error is thrown:
This error is thrown in the SpriteRender module.
Is Webpack required here and some build steps not explained in the readme? Would be great if it worked as is in Electron, without any additional build steps and requirements if possible.
Phaser v3.5.1, Electron v1.8.4.
The text was updated successfully, but these errors were encountered: