A template for svelte+rust wasm applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Jordan Gregory e2317dfb2e
tweak the template just a touch
11 months ago
public remove image for reasons lol 1 year ago
src tweak the template just a touch 11 months ago
.gitignore init 1 year ago
README.md update readme to call out the branch in the cargo generate command 1 year ago
package-lock.json it's alive 1 year ago
package.json make this more of a cargo generate template 1 year ago
rollup.config.js it's alive 1 year ago

README.md

Svelte + Rust (WASM) App Template

This is a project template for Svelte apps that integrates Rust (WASM) as well.

To create a new project based on this template using cargo-generate:

cargo generate --git https://git.stlrust.org/j4ng5y/svelte-wasm-template --branch main --name <my app name>
cd <my app name>

Prereqs

  • Cargo-generate installed (just to get the template -- cargo install cargo-generate)
  • Node.js installed
  • Rust installed
  • wasm-pack installed

Get Started

Install the dependencies...

cd <my app name>
npm install

...then start Rollup:

npm run dev

Navigate to localhost:5000. You should see your app running. Edit a Svelte component file in src, or the WASM component in src/greeting/src, save it, restart the dev server to recompile the WASM, and then reload your page to see your changes.

By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the sirv commands in package.json to include the option --host 0.0.0.0.

If you’re using VSCode, we recommend installing the offical Svelte extension as well as the offical Rust extension. If you are using other editors, your may need to install a plugin in order to get syntax highlighting and intellisense for both Svelte and Rust.

Building and running in production mode

To create an optimized version of the app:

npm run build

You can run the newly built app with npm run start. This uses sirv, which is invluded in your package.json's dependencies so that the app will work with you deploy to platforms like Heroku.

Single-page app mode

By default, sirv will only respond to requests that match files in public. This is to maximize compatibility with static file servers, allowing you to deploy your app almost anywhere.

If you’re building a single-page application (SPA) with multiple routes, sirv needs to be able to respond to requests for ANY path. You can make it so by editing the start command in package.json:

"start": "sirv public --single"

Deployment

I’ll write this section as soon as I deploy it 😄