slightly speed up the bundle and add support for min.js
Improve performance by loading plugins slower Automatically build .min.js bundle file
This commit is contained in:
parent
4a89036821
commit
42243ff2d5
3 changed files with 36 additions and 21 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue