Print hash of files when building

This commit is contained in:
coletdjnz
2025-09-26 18:21:51 +12:00
parent e5f5f79cdd
commit 3655915fc1

View File

@@ -2,6 +2,26 @@ import { defineConfig } from "rollup";
import nodeResolve from "@rollup/plugin-node-resolve";
import sucrase from "@rollup/plugin-sucrase";
import terser from "@rollup/plugin-terser";
import { createHash } from "node:crypto";
function printHash() {
return {
name: "hash-output-plugin",
async writeBundle(options, bundle) {
for (const [fileName, assetInfo] of Object.entries(bundle)) {
if (assetInfo.code) {
try {
const data = Buffer.from(assetInfo.code)
const hash = createHash("sha3-512").update(data).digest("hex");
console.log(`SHA3-512 for ${assetInfo.fileName}: ${hash}`);
} catch (err) {
console.error(`Error hashing ${fileName}:`, err.message);
}
}
}
},
};
}
export default defineConfig([
{
@@ -23,6 +43,7 @@ export default defineConfig([
exclude: ["node_modules/**"],
transforms: ["typescript"],
}),
printHash(),
],
},
{
@@ -47,6 +68,7 @@ export default defineConfig([
transforms: ["typescript"],
}),
terser(),
printHash(),
],
},
{
@@ -63,6 +85,7 @@ export default defineConfig([
exclude: ["node_modules/**"],
transforms: ["typescript"],
}),
printHash(),
],
},
{
@@ -81,6 +104,7 @@ export default defineConfig([
transforms: ["typescript"],
}),
terser(),
printHash(),
],
},
]);