1.0.2 • Published 5 months ago

vite-plugin-build-hash v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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')`
      },
    ),
  ],
};
1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago