From 42243ff2d544c34fb347adb02ca8ba7289ace804 Mon Sep 17 00:00:00 2001 From: kmmiio99o <164557248+kmmiio99o@users.noreply.github.com> Date: Sat, 15 Nov 2025 17:16:20 +0100 Subject: [PATCH] slightly speed up the bundle and add support for min.js Improve performance by loading plugins slower Automatically build .min.js bundle file --- scripts/build.mjs | 19 +++++++------------ scripts/serve.mjs | 32 ++++++++++++++++++++++++++------ src/index.ts | 6 +++--- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 07946b4..1f8cd4a 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -35,16 +35,13 @@ const config = { splitting: false, // Enable minification by default for release builds (when a release-branch is provided). // This keeps development builds unminified for easier debugging. - minify: Boolean(releaseBranch), + minify: true, external: [], supported: { // Hermes does not actually support const and let, even though it syntactically // accepts it, but it's treated just like 'var' and causes issues "const-and-let": false, }, - footer: { - js: "//# sourceURL=shiggycord", - }, loader: { ".png": "dataurl", }, @@ -77,7 +74,7 @@ const config = { constModules: { globals: { "bunny-build-info": { - version: `"1.1.10-4"`, + version: `"1.1.10-5"`, }, }, }, @@ -142,12 +139,10 @@ if (isThisFileBeingRunViaCLI) { printBuildSuccess(context.hash, releaseBranch, timeTook); - if (buildMinify) { - const { timeTook } = await buildBundle({ - minify: true, - outfile: config.outfile.replace(/\.js$/, ".min.js"), - }); + const { timeTook: minifiedTimeTook } = await buildBundle({ + minify: true, + outfile: config.outfile.replace(/\.js$/, ".min.js"), + }); - printBuildSuccess(context.hash, releaseBranch, timeTook, true); - } + printBuildSuccess(context.hash, releaseBranch, minifiedTimeTook, true); } diff --git a/scripts/serve.mjs b/scripts/serve.mjs index 590c3e0..6458fa6 100644 --- a/scripts/serve.mjs +++ b/scripts/serve.mjs @@ -18,13 +18,32 @@ export function serve(options) { const { pathname } = url.parse(req.url || "", true); if (pathname?.endsWith(".js")) { try { - const { config, context, timeTook } = await buildBundle(); - - printBuildSuccess(context.hash, args.production, timeTook); + let fileToServe; + if (pathname === "/shiggycord.min.js") { + const { config, context, timeTook } = await buildBundle({ + minify: true, + }); + printBuildSuccess( + context.hash, + args["release-branch"], + timeTook, + true, + ); + fileToServe = config.outfile.replace(/\.js$/, ".min.js"); + } else if (pathname === "/shiggycord.js") { + const { config, context, timeTook } = await buildBundle(); + printBuildSuccess(context.hash, args["release-branch"], timeTook); + fileToServe = config.outfile; + } else { + res.writeHead(404); + res.end(); + return; + } res.writeHead(200, { "Content-Type": "application/javascript" }); - res.end(await readFile(config.outfile, "utf-8")); - } catch { + res.end(await readFile(fileToServe, "utf-8")); + } catch (error) { + console.error("Error serving bundle:", error); res.writeHead(500); res.end(); } @@ -42,8 +61,9 @@ export function serve(options) { for (const netinterfaces of Object.values(netInterfaces)) { for (const details of netinterfaces || []) { if (details.family !== "IPv4") continue; - const port = chalk.green(server.address()?.port.toString()); + const port = chalk.green((args.port ?? 4040).toString()); console.info(` http://${details.address}:${port}/shiggycord.js`); + console.info(` http://${details.address}:${port}/shiggycord.min.js`); } } diff --git a/src/index.ts b/src/index.ts index b51122d..9e1a300 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,9 +3,7 @@ import initFixes from "@core/fixes"; import { initFetchI18nStrings } from "@core/i18n"; import initSettings from "@core/ui/settings"; import { initVendettaObject } from "@core/vendetta/api"; -import { VdPluginManager } from "@core/vendetta/plugins"; import { updateFonts } from "@lib/addons/fonts"; -import { initPlugins, updatePlugins } from "@lib/addons/plugins"; import { initThemes } from "@lib/addons/themes"; import { patchCommands } from "@lib/api/commands"; import { patchLogHook } from "@lib/api/debug"; @@ -40,7 +38,6 @@ export default async () => { initFetchI18nStrings(), initSettings(), initFixes(), - // Do NOT run updatePlugins here — that is deferred. ]; // Run critical inits and collect unpatchers/cleanup handlers. @@ -60,6 +57,9 @@ export default async () => { // Deferred work: run after interactions to avoid blocking initial paint and navigation. const runDeferred = async () => { + const { VdPluginManager } = await import("@core/vendetta/plugins"); + const { initPlugins, updatePlugins } = await import("@lib/addons/plugins"); + // Initialize Vendetta plugins (may start many plugins) — do not block UI. VdPluginManager.initPlugins() .then((u) => lib.unload.push(u))