Skip to content

Instantly share code, notes, and snippets.

@iamparthaonline
Created January 6, 2025 07:25
Show Gist options
  • Select an option

  • Save iamparthaonline/200a4f80c584bc6beb0673f05243eff4 to your computer and use it in GitHub Desktop.

Select an option

Save iamparthaonline/200a4f80c584bc6beb0673f05243eff4 to your computer and use it in GitHub Desktop.
/* add in you package json build script like this -
"build": "vite build && node bundle.js",
*/
import fs from "fs";
import archiver from "archiver";
import { DateTime } from "luxon";
var output = fs.createWriteStream("dist.zip");
var archive = archiver("zip");
Number.prototype.formatBytes = function () {
var units = ["B", "KB", "MB", "GB", "TB"],
bytes = this,
i;
for (i = 0; bytes >= 1024 && i < 4; i++) {
bytes /= 1024;
}
return bytes.toFixed(2) + units[i];
};
output.on("close", function () {
var size = Number(archive.pointer());
console.log("Successfully bundled! Bundle Size: ", size.formatBytes());
});
archive.on("error", function (err) {
throw err;
});
archive.pipe(output);
//add version information
const version = JSON.stringify({
releasedOn: DateTime.now().toFormat("MMMM dd, yyyy"),
});
const filepath = "./dist/release.json";
console.log("version", version);
fs.writeFileSync(filepath, version);
// archive the dist directory
archive.directory("./dist", false);
archive.finalize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment