I’m not very familiar with Webpack, but I have decided to start using it at the same time as moving from Phaser 2 to Phaser 3 and I’m having some newbie doubts.
The main problem I’m having at the moment is using
import Phaser from 'phaser'
on the project causes the build process to import the default build of Phaser and include it in the minified code everytime I run the build command.
On one hand this includes unnecessary code as, for example, I don’t need the physics part (with Phaser 2 I would just manually add the phaser-no-physics.min.js dist file). On the other hand it makes the build process a lot heavier, since running through the whole Phaser code takes way longer than just running it through the game code.
I checked the webpack phaser3 template and it does this, so I was wondering if this is the right way to import Phaser 3 or if there is a better approach that I am missing.
Thanks in advance for your help!
You can use Webpack’s externals
feature to fix this. If you declare Phaser as an external, you can load it from a <script>
tag in your HTML (instead of building it along with your game) and retain the ability to import
it.
1 Like
Thanks Telinc1, that sounds exactly like what I needed.
For development purposes, I run nodemon on the main file in package.json:
“develop”: “cross-env NODE_ENV=development nodemon src/server/serverDev.js”,
in the main file.js I have:
//Develop setup Webpack, needed for realtime compilation
const compiler = webpack(webpackConfig)
app.use(webpackDevMiddleware(compiler))
I do have the problem that on fast pc’s it 5second on changes, up to 20s wait time on slow pc’s
Webpack is imo more for builds of end products (?)
Wouldn’t running Webpack in development mode be equivalent?
Yes I combine a dev webpack config with nodemon. That seems the fastest somehow…
Don’t know how to run without webpack.
I was questioning the usefulness of nodemon in this case. Webpack can watch files for changes by itself, unless you constantly need to edit its config for some reason.