Try to not load terser in the main thread?

This commit is contained in:
Jade Ellis 2024-06-16 18:54:59 +01:00
parent e5aa809a07
commit 9351d7ebeb
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2

View file

@ -1,6 +1,7 @@
import type { MinifyOptions, MinifyOutput } from "terser";
import { recieveMessageData, sendMessageData } from "./util";
const is_browser = typeof window !== "undefined";
export function init() {
let worker: SharedWorker;
@ -36,11 +37,13 @@ export function init() {
worker.port.postMessage(data)
});
} else {
} else if (is_browser) {
if (!terserModule) {
terserModule = await import("terser")
}
return await terserModule.minify(files, options)
} else {
return {}
}
}
}