diff --git a/Cargo.toml b/Cargo.toml index 2a7056b..69b7a64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ edition = "2018" [lib] crate-type = ["cdylib"] + [dependencies] -seed = "^0.1.8" +seed = "^0.1.12" wasm-bindgen = "^0.2.29" web-sys = "^0.3.6" # For serialization, eg sending requests to a server. Otherwise, not required. -serde = "^1.0.80" -serde_derive = "^1.0.80" -serde_json = "1.0.33" \ No newline at end of file +serde = { version = "^1.0.80", features = ['derive'] } +serde_json = "^1.0.33" \ No newline at end of file diff --git a/README.md b/README.md index d3d00f1..b1c7792 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,18 @@ `cargo install wasm-bindgen-cli` +If you run into errors while installing `wasm-bindgen-cli`, you may need to install a C++ +build chain. On linux, run `sudo apt install build-essential`. On Windows, download and install +[Visual Studio 2017](https://visualstudio.microsoft.com/downloads/); when asked in the installer, +include the C++ workload. + - Run `build.sh` or `build.ps1`, then then start a dev server that supports WASM. For example, with [Python](https://www.python.org/downloads/) installed, run `python pyserve.py`. (Linux users may need to run `python3 serve.py`.) +If you run into permission errors on `build.sh`, try this command +to allow executing the file:`chmod +x build.sh`. If you run into persmission errors on `build.ps`, open Powershell as an administrator, and enter this command: `Set-ExecutionPolicy RemoteSigned`. + Once you rename the crate in `Cargo.toml` (The `name` field under `[Package]`), make the following changes: diff --git a/serve.py b/serve.py index bae62e9..9506a59 100644 --- a/serve.py +++ b/serve.py @@ -1,13 +1,27 @@ #!/usr/bin/env python3 -# From https://gist.github.com/prideout/09af26cef84eef3e06a1e3f20a499a48 - import http.server +import os import socketserver +import urllib PORT = 8000 -handler = http.server.SimpleHTTPRequestHandler + +class Handler(http.server.SimpleHTTPRequestHandler): + # Allow SPA routing by redirecting subpaths. + def do_GET(self): + urlparts = urllib.parse.urlparse(self.path) + request_file_path = urlparts.path.strip('/') + + if not os.path.exists(request_file_path): + self.path = 'index.html' + + return http.server.SimpleHTTPRequestHandler.do_GET(self) + + +handler = Handler +# Add support for the WASM mime type. handler.extensions_map.update({ '.wasm': 'application/wasm', }) @@ -16,4 +30,4 @@ socketserver.TCPServer.allow_reuse_address = True with socketserver.TCPServer(("", PORT), handler) as httpd: httpd.allow_reuse_address = True print("Serving at port", PORT) - httpd.serve_forever() \ No newline at end of file + httpd.serve_forever() diff --git a/src/lib.rs b/src/lib.rs index 170ce97..0d41707 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ fn update(msg: Msg, model: Model) -> Model { // View -fn view(model: Model) -> El { +fn view(app: seed::App, model: Model) -> El { button![ simple_ev("click", Msg::Increment), format!("Hello, World × {}", model.val)