diff --git a/both_basic/both.html b/both_basic/both.html new file mode 100644 index 0000000..eac896f --- /dev/null +++ b/both_basic/both.html @@ -0,0 +1,14 @@ + + + + + + Supporting Both Chrome And Node Sandbox + + + +
+ + + + diff --git a/both_basic/both.mjs b/both_basic/both.mjs new file mode 100644 index 0000000..49f835b --- /dev/null +++ b/both_basic/both.mjs @@ -0,0 +1,4 @@ +async function main() { + console.log("I am main!"); +} +export { main }; diff --git a/both_basic/both_chrome.mjs b/both_basic/both_chrome.mjs new file mode 100644 index 0000000..9af059a --- /dev/null +++ b/both_basic/both_chrome.mjs @@ -0,0 +1,9 @@ +import { main } from "http://localhost:8000/webgpu-sandbox/both/both.mjs"; +if (typeof process !== "undefined" && process.release.name === "node") { + // running in Node + alert("Use this only from a web browser."); +} else { + // running in browser +} + +main(); diff --git a/both_basic/both_node.mjs b/both_basic/both_node.mjs new file mode 100644 index 0000000..a935566 --- /dev/null +++ b/both_basic/both_node.mjs @@ -0,0 +1,9 @@ +import { main } from "./both.mjs"; +if (typeof process !== "undefined" && process.release.name === "node") { + // running in Node +} else { + // running in browser + alert("Use this only in Node."); +} + +main();