Sign in to follow this  
mike perry

Multiplayer game - the "script" element could not be loaded

Recommended Posts

How do you configure the server for this template ? => https://github.com/nkholski/phaser3-es6-webpack
I'm trying to do it by following this tutorial => https://gamedevacademy.org/create-a-basic-multiplayer-game-in-phaser-3-with-socket-io-part-1/?a=13
I added two dependencies: nodemon and express.
I created the server.js file with the server configuration.

const express = require('express')
const app = express()
const server = require('http').Server(app)
const path = require('path')

app.get('/', function(req, res) {
res.sendFile(path.resolve('index.html'))
})  

server.listen(8081, function() {
console.log(`Listening on ${server.address().port}`)
})

In the package.json file, I added a command to start the server:

nodemon src/server/server.js

The server starts correctly but the indicated html file can not read the scripts (" The load failed for the "script" element with the source vendor.js and app.js").

Project structure: r4QcXoJ.png

Share this post


Link to post
Share on other sites

Thanks for reply.
I solved this problem by indicate to the folder in which the scripts are located .
In my case it was a folder called 'dev'.
Adding this line solved the problem:

app.use('/dev', express.static('dev'))

Additional question
Is there any way to run webpack only for build scripts not for running webpack server?
The node server needs scripts to open the HTML file correctly.
Scripts are built by running webpack in development mode.

Is it good practise if I start webpack and node server with one command?
Something like below (using "start").

    "start": "concurrently --kill-others \"npm run dev\" \"npm run server\"",
    "dev": "webpack --mode=development",
    "deploy": "webpack  --mode=production --config webpack.production.config.js",
    "server": "nodemon ./src/server/server.js --exec babel-node",

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.