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