Wasm-Pack Angular Component Import

PHOTO EMBED

Mon Jul 11 2022 18:59:17 GMT+0000 (Coordinated Universal Time)

Saved by @Polly #rust #wasm #wasm-pack #angular

# method 1
import * as wasm from 'wasm/pkg'

ngOnInit()
  wasm.greet()


#method 2
import { greet } from 'wasm/pkg/wasm_bg.wasm'; #|| from 'wasm/pkg'
  ngOnInit()
    greet()

# method 3
ngOnInit() {
  const rust = import('../../wasm/pkg');
  rust.then(m => m.greet()).catch(console.error);

  rust.then(m => console.log(m.add(2, 2), 'added'));
}

# Terminal command to build lib.rs 
wasm-pack build
content_copyCOPY

this command fails in my setup: wasm-pack build --target web

https://rustwasm.github.io/docs/book/game-of-life/hello-world.html