vite-plugin-build-hash
v1.0.2
Published
vite plugin to generate a deterministic hash of your build output
Downloads
8
Readme
vite-plugin-build-hash
vite plugin to generate a deterministic hash of your build output
Install
yarn add -D vite-plugin-build-hash
Usage
// vite.config.ts
import fs from "node:fs/promises";
import path from "node:path";
import buildHash from 'vite-plugin-build-hash';
export default {
plugins: [
buildHash(async (hash) => {
await fs.writeFile(
path.join(__dirname, 'dist', 'version.json'),
JSON.stringify({
buildHash: hash.digest('hex'),
}),
);
}),
],
};
Options
// vite.config.ts
import fs from "node:fs/promises";
import path from "node:path";
import buildHash from "vite-plugin-build-hash";
const outDir = "build";
export default {
plugins: [
buildHash(
async (hash) => {
await fs.writeFile(
path.join(__dirname, outDir, 'version.json')
JSON.stringify({
buildHash: hash.digest("hex"),
}),
);
},
{
outDir, // default `dist`
contents: true, // controls whether contents are used for hashing or just file names. default `false`
createHash: () => crypto.createHash("512"), // default `() => crypto.createHash('256')`
},
),
],
};