Skip to content

Instantly share code, notes, and snippets.

@tpmccallum
Last active February 1, 2020 05:48
Show Gist options
  • Select an option

  • Save tpmccallum/f7e4f3559a76896c8e9896dea6f67df0 to your computer and use it in GitHub Desktop.

Select an option

Save tpmccallum/f7e4f3559a76896c8e9896dea6f67df0 to your computer and use it in GitHub Desktop.

#System housekeeping

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential
sudo apt-get -y install curl
#Install Node and NPM
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install npm
#Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
#Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf |
sudo apt-get install pkg-config
sudo apt-get install libssl-dev
cargo install cargo-generate
cargo generate --git https://github.com/rustwasm/wasm-pack-template

Thankfull this wasm-pack template that we just generated actually has all of the code that you will need. Now that we have all of our code, we need to package it all up. This way, we can publish all of this to npmjs.com. To do this, run the following command (noting that the last argument is your npm username)

wasm-pack build --scope tpmccallum

To log into your npm account, via wasm-pack simply type the following command wasm-pack login

Then change to the pkg directory and publish

cd pkg
npm publish --access=public

Ok, so we have published a package. Let's now go ahead and create an application that we can use it in. Please note, we are using a template, so don't make up your own app name, use the create-wasm-app text as shown below.

cd ~
npm init wasm-app create-wasm-app

Then open the package.json file and replace the template's hello-wasm-pack dependancy with your own.

cd ~
cd create-wasm-app
vi package.json

Or just install it via the terminal (which will add it as a dependency)

npm i @tpmccallum/tpmccallum-greet
// snip

"devDependencies": {
   "tpmccallum-greet": "^0.1.0",

//snip

Finally, open the index.json and insert your package name, as directed.

import * as wasm from "tpmccallum-greet";
  
wasm.greet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment