Skip to content

Commit a3b63cb

Browse files
committed
Use electron-vite's ?modulePath instead of tsx for workers
electron-vite has a `?modulePath` vite plugin that compiles the import and returns an absolute path, so we don't need to use tsx to compile and execute the typescript directly. Vanilla vite has a `?worker` plugin but that's only for webworkers; support for node workers is stalled (vitejs/vite#3932).
1 parent 5fbc02d commit a3b63cb

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"jsdom": "^26.1.0",
6464
"prettier": "3.6.0",
6565
"testcontainers": "^11.2.1",
66-
"tsx": "^4.20.5",
6766
"typescript": "~5.8.3",
6867
"typescript-eslint": "^8.35.0",
6968
"vite": "^7.0.0",

app/pnpm-lock.yaml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/index.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import "source-map-support/register";
22
import { app, BrowserWindow, ipcMain } from "electron";
33
import { join } from "path";
4+
import { Worker } from "worker_threads";
45
import { optimizer, is } from "@electron-toolkit/utils";
56
import {
67
installExtension,
78
REDUX_DEVTOOLS,
89
REACT_DEVELOPER_TOOLS,
910
} from "electron-devtools-installer";
10-
import { Worker } from "worker_threads";
11+
import workerPath from "./fetch/worker?modulePath";
1112

1213
import { DB } from "./database";
1314
import { proxy } from "./proxy";
@@ -59,16 +60,7 @@ function createWindow(): void {
5960
}
6061

6162
function spawnFetchWorker(): Worker {
62-
const scriptPath = join(
63-
app.getAppPath(),
64-
"src",
65-
"main",
66-
"fetch",
67-
"worker.ts",
68-
);
69-
const worker = new Worker(scriptPath, {
70-
execArgv: ["--require", "tsx"],
71-
});
63+
const worker = new Worker(workerPath);
7264

7365
worker.on("message", (result) => {
7466
console.log("Result from worker: ", result);

0 commit comments

Comments
 (0)