mirror of https://github.com/sotrh/learn-wgpu
example loading in vuepress
parent
f25377f38b
commit
ba9147f654
@ -1,10 +1 @@
|
||||
#!/usr/bin/env bash
|
||||
# Adapted from https://github.com/gfx-rs/wgpu/blob/master/run-wasm-example.sh
|
||||
|
||||
set -e
|
||||
|
||||
cargo build --bin pong --target wasm32-unknown-unknown
|
||||
|
||||
mkdir -p target/wasm-examples/pong
|
||||
wasm-bindgen --target web --out-dir target/wasm-examples/pong target/wasm32-unknown-unknown/debug/pong.wasm
|
||||
cp index.template.html target/wasm-examples/pong/index.html
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/pong code/showcase/pong
|
||||
|
@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<div class="wasm-example">
|
||||
<div class="error" v-if="error">
|
||||
{{ error }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: { example: "" },
|
||||
data() {
|
||||
return {
|
||||
error: {
|
||||
value: "",
|
||||
required: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
await this.$nextTick();
|
||||
|
||||
try {
|
||||
const init = await import(`./wasm/${this.example}/${this.example}.js`);
|
||||
init().then(() => {
|
||||
console.log("WASM Loaded");
|
||||
});
|
||||
} catch (e) {
|
||||
this.error = `An error occurred loading "${this.example}": ${e}`;
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue