File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1028,7 +1028,7 @@ namespace webcc
10281028
10291029 void generate_html (const std::string &out_dir, const std::string &template_path)
10301030 {
1031- const std::string script_tag = " <script src=\" /app.js\" ></script>" ;
1031+ const std::string script_tag = " <script src=\" . /app.js\" ></script>" ;
10321032 std::string html;
10331033
10341034 // Try to find a custom template
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ const supportsStreaming = () => {
1717};
1818
1919const run = async () => {
20+ const scriptSrc = document.currentScript && document.currentScript.src;
21+ const assetBase = new URL('.', scriptSrc || window.location.href);
22+ const wasmUrl = new URL('app.wasm', assetBase);
23+
2024 const imports = {
2125 env: {
2226 // C++ calls this function to tell JS "I wrote commands, please execute them"
@@ -35,9 +39,9 @@ const run = async () => {
3539
3640 let mod;
3741 if (supportsStreaming()) {
38- mod = await WebAssembly.instantiateStreaming(fetch('/app.wasm' ), imports);
42+ mod = await WebAssembly.instantiateStreaming(fetch(wasmUrl ), imports);
3943 } else {
40- const response = await fetch('/app.wasm' );
44+ const response = await fetch(wasmUrl );
4145 const bytes = await response.arrayBuffer();
4246 mod = await WebAssembly.instantiate(bytes, imports);
4347 }
You can’t perform that action at this time.
0 commit comments