Setup example worker

This commit is contained in:
Schluffe
2026-09-27 18:09:53 +02:00
parent a647cd5184
commit d57c58a3bd
4 changed files with 24 additions and 2 deletions
+2 -1
View File
@@ -17,7 +17,8 @@
"suspicious": {
"noTsIgnore": "off",
"noAssignInExpressions": "off",
"noFallthroughSwitchClause": "warn"
"noFallthroughSwitchClause": "warn",
"noGlobalAssign": "warn"
},
"correctness": {
"useParseIntRadix": "off",
+9
View File
@@ -85,3 +85,12 @@ function animate(timestamp: number): void {
animate(delta);
})();
const worker = new Worker(new URL("./worker.ts", import.meta.url), {
type: "module",
});
worker.onmessage = (event) => {
console.log(event.data);
};
worker.postMessage("foo");
+7 -1
View File
@@ -18,7 +18,13 @@ function devTools(): Plugin {
export default defineConfig({
server: { host, port, hmr: false },
build: { target: "esnext" },
build: {
target: "esnext",
main: `${root}index.html`,
lib: {
entry: `${root}worker.ts`,
},
},
test: {
include: ["./engine/**/*.test.ts"],
environment: "jsdom",
+6
View File
@@ -0,0 +1,6 @@
// biome-ignore lint: web worker
onmessage = (event) => {
if (event.data === "foo") {
postMessage("bar");
}
};