Skip to content

Instantly share code, notes, and snippets.

@surma surma/.gitignore Secret
Last active Aug 9, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.