Skip to content
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

1. Building for the web (hosting suggestion) #215

Open
ajmedeio opened this issue Nov 2, 2023 · 1 comment
Open

1. Building for the web (hosting suggestion) #215

ajmedeio opened this issue Nov 2, 2023 · 1 comment

Comments

@ajmedeio
Copy link

ajmedeio commented Nov 2, 2023

@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
Copy link
Author

ajmedeio commented Nov 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant