rustrogueliketutorial icon indicating copy to clipboard operation
rustrogueliketutorial copied to clipboard

1. Building for the web (hosting suggestion)

Open ajmedeio opened this issue 2 years ago • 1 comments

@thebracket You make a request on the first section to recommend local hosting options. I used a docker image and hosted there. For example:

# project_root/Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install nginx -y
COPY wasm/* /var/www/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# project_root
docker build -t local-wasm-host .
docker run -d -p 8000:80 --name local-wasm-host local-wasm-host

Open a browser to http://localhost:8000 and I think it works. I'm just starting the tutorial though so don't have anything showing yet.

ajmedeio avatar Nov 02 '23 20:11 ajmedeio

I came across a better solution:

cargo install wasm-server-runner

And configure our project to use it by adding a new file, .cargo/config.toml:

[target.wasm32-unknown-unknown] runner = "wasm-server-runner"

Now, when we run the project for the wasm target, it will start a local web server and log the link in the terminal:

$ cargo run --target wasm32-unknown-unknown Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running wasm-server-runner target\wasm32-unknown-unknown\debug\extreme_bevy.wasm INFO wasm_server_runner: compressed wasm output is 11.67mb large INFO wasm_server_runner::server: starting webserver at http://127.0.0.1:1334

Source: https://johanhelsing.studio/posts/extreme-bevy

ajmedeio avatar Nov 03 '23 20:11 ajmedeio