# laravel-mix-make-file-hash

> Convert the default Laravel Mix querystring hashing to filename hashing.

Latest version **2.2.0** (published 2020-11-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install laravel-mix-make-file-hash
pnpm add laravel-mix-make-file-hash
yarn add laravel-mix-make-file-hash
bun add laravel-mix-make-file-hash
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2020-11-01 |
| First published | 2019-06-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Ben Rogerson |
| Maintainers | ben-rogerson |
| Keywords | laravel, mix, hashing, hash, file, filehash |

## Links

- npm: https://www.npmjs.com/package/laravel-mix-make-file-hash
- Repository: https://github.com/ben-rogerson/laravel-mix-make-file-hash
- Homepage: https://github.com/ben-rogerson/laravel-mix-make-file-hash#readme
- Issues: https://github.com/ben-rogerson/laravel-mix-make-file-hash/issues
- npm.io page: https://npm.io/package/laravel-mix-make-file-hash

## Dependencies (2)

- [del](https://npm.io/package/del.md) ^5.1.0
- [micromatch](https://npm.io/package/micromatch.md) ^4.0.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.2.0 (latest) — 2020-11-01
- 2.1.0 — 2020-02-01
- 2.0.2 — 2020-01-28
- 2.0.0 — 2020-01-28
- 1.2.0 — 2019-07-19
- 1.1.1 — 2019-06-27
- 1.1.0 — 2019-06-27

## README

# Laravel Mix make file hash

By default, the hashing system in Laravel Mix will append a querystring to the filename to invalidate the cache.

Example from `mix-manifest.json`:

```json
{
  "/dist/main.js": "/dist/main.js?id=1e70e7c11a9185f57e64"
}
```

The problem is that this way of hashing may not work with some caching systems.

Instead, **"Laravel Mix make file hash" will move the hash into the filename of the hashed files**. So your `mix-manifest.json` will look something like this:

```json
{
  "/dist/main.js": "/dist/main.1e70e7c11a9185f57e64.js"
}
```

## Under the hood

To accomplish the re-hashing, this script will:

1. Read the `mix-manifest.json` generated by Laravel Mix.
2. Remove stale hashed files.
3. Rename the files found in the manifest to include the hash within the filename.
4. Update `mix-manifest.json` with the new filenames.
5. Return the contents of the new manifest for further usage (if required).

Turn on debug to activate noisy feedback:
`{ debug: true }`

## Installation

Install package from [npmjs.com](https://www.npmjs.com/package/laravel-mix-make-file-hash):

```bash
npm i -D laravel-mix-make-file-hash
# or
yarn add laravel-mix-make-file-hash -D
```

## Normal usage

```js
if (mix.inProduction()) {
  mix.version();
  mix.then(() => {
    const convertToFileHash = require("laravel-mix-make-file-hash");
    convertToFileHash({
      publicPath: "web",
      manifestFilePath: "web/mix-manifest.json"
    });
  });
}
```

## Promise usage

`convertToFileHash` returns a Promise containing the new `mix-manifest.json` contents. This means you can perform another task after the `convertToFileHash` has finished the re-hashing.

```js
if (mix.inProduction()) {
  mix.version();
  mix.then(async () => {
    const convertToFileHash = require("laravel-mix-make-file-hash");
    const fileHashedManifest = await convertToFileHash({
      publicPath: "web",
      manifestFilePath: "web/mix-manifest.json"
    });
    // Do something here...
  });
}
```

## Options

| Name                   | Type             | Default            | Description                                                                          |
| ---------------------- | ---------------- | ------------------ | ------------------------------------------------------------------------------------ |
| publicPath \*          | `string`         | `undefined`        | The path to your public folder (eg: `"web"`)                                         |
| manifestFilePath \*    | `string`         | `undefined`        | The filePath to your mix-manifest.json<br /> (eg: `"web/mix-manifest.json"`)         |
| blacklist              | `string`/`array` | `undefined`        | A glob pattern of files to ignore re-hashing                                         |
| keepBlacklistedEntries | `boolean`        | `false`            | Whether to keep blacklisted entries in the manifest                                  |
| delOptions             | `object`         | `{ force: false }` | Options to provide to del - [See options](https://www.npmjs.com/package/del#options) |
| debug                  | `boolean`        | `false`            | Debug exactly what's happening (or meant to happen) during runtime                   |

\*&nbsp;= Required

## Full config example

```js
if (mix.inProduction()) {
  mix.version();
  mix.then(async () => {
        const convertToFileHash = require("laravel-mix-make-file-hash");
        convertToFileHash({
            publicPath: "web",
            manifestFilePath: "web/mix-manifest.json",
            blacklist: ["html", "main.js"],
            keepBlacklistedEntries: true,
            delOptions: { force: false },
            debug: false
        });
  })
```

## Links

This script was created for the [Agency Webpack Mix Config](https://github.com/ben-rogerson/agency-webpack-mix-config).

---
_Source: https://npm.io/package/laravel-mix-make-file-hash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
