mirror of
https://github.com/Davilarek/Vencord.git
synced 2025-05-11 18:05:41 +02:00
Optimise Web via treeshaking, cleanup build scripts
This commit is contained in:
parent
845088ec02
commit
01ae0983b3
14 changed files with 261 additions and 269 deletions
61
scripts/build/buildWeb.mjs
Normal file
61
scripts/build/buildWeb.mjs
Normal file
|
@ -0,0 +1,61 @@
|
|||
// TODO: Modularise the plugins since both build scripts use them
|
||||
|
||||
import { createWriteStream, readFileSync } from "fs";
|
||||
import yazl from "yazl";
|
||||
import esbuild from "esbuild";
|
||||
// wtf is this assert syntax
|
||||
import PackageJSON from "../../package.json" assert { type: "json" };
|
||||
import { commonOpts, gitHashPlugin, globPlugins } from "./common.mjs";
|
||||
|
||||
/**
|
||||
* @type {esbuild.BuildOptions}
|
||||
*/
|
||||
const commonOptions = {
|
||||
...commonOpts,
|
||||
entryPoints: ["browser/Vencord.ts"],
|
||||
globalName: "Vencord",
|
||||
format: "iife",
|
||||
minify: true,
|
||||
sourcemap: false,
|
||||
external: ["plugins", "git-hash"],
|
||||
plugins: [
|
||||
globPlugins,
|
||||
gitHashPlugin
|
||||
],
|
||||
target: ["esnext"],
|
||||
define: {
|
||||
IS_WEB: "true"
|
||||
}
|
||||
};
|
||||
|
||||
await Promise.all(
|
||||
[
|
||||
esbuild.build({
|
||||
...commonOptions,
|
||||
outfile: "dist/browser.js",
|
||||
footer: { js: "//# sourceURL=VencordWeb" },
|
||||
}),
|
||||
esbuild.build({
|
||||
...commonOptions,
|
||||
outfile: "dist/Vencord.user.js",
|
||||
banner: {
|
||||
js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", PackageJSON.version)
|
||||
},
|
||||
footer: {
|
||||
// UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local
|
||||
js: "Object.defineProperty(window,'Vencord',{get:()=>Vencord});"
|
||||
},
|
||||
})
|
||||
]
|
||||
);
|
||||
|
||||
const zip = new yazl.ZipFile();
|
||||
zip.outputStream.pipe(createWriteStream("dist/extension.zip")).on("close", () => {
|
||||
console.info("Extension written to dist/extension.zip");
|
||||
});
|
||||
|
||||
zip.addFile("dist/browser.js", "dist/Vencord.js");
|
||||
["background.js", "content.js", "manifest.json"].forEach(f => {
|
||||
zip.addFile(`browser/${f}`, `${f}`);
|
||||
});
|
||||
zip.end();
|
Loading…
Add table
Add a link
Reference in a new issue