Skip to content

Instantly share code, notes, and snippets.

@surma

surma/.gitignore Secret

Last active February 12, 2022 12:37
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surma/a02db7b53eb3e7870bf539b906ff6ff6 to your computer and use it in GitHub Desktop.
Save surma/a02db7b53eb3e7870bf539b906ff6ff6 to your computer and use it in GitHub Desktop.
package-lock.json
node_modules
dist
<!doctype html>
<script src="main.js" defer></script>
import { wrap } from "comlink";
async function init() {
const worker = new Worker("./worker.js");
const api = wrap(worker);
const result = await api.add(40, 2);
alert(`Result: ${result}`);
}
init();
{
"name": "omt-demo",
"version": "0.0.1",
"description": "",
"private": true,
"scripts": {
"build": "rollup -c && cp index.html dist",
"serve": "http-server -c0 dist"
},
"keywords": [],
"author": "Surma <surma@surma.link>",
"license": "Apache-2.0",
"dependencies": {
"comlink": "^4.0.1",
"rollup": "^1.17.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-off-main-thread": "^1.0.0"
},
"devDependencies": {
"http-server": "^0.11.1"
}
}
import nodeResolve from "rollup-plugin-node-resolve";
import OMT from "rollup-plugin-off-main-thread";
export default {
input: "main.js",
output: {
dir: "dist",
format: "amd"
},
plugins: [
nodeResolve(),
OMT()
]
}
import { expose } from "comlink";
class API {
static add(a, b) {
return a + b;
}
}
expose(API);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment