New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

laravel-mix-make-file-hash

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laravel-mix-make-file-hash

Convert the default Laravel Mix querystring hashing to filename hashing.

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.2K
increased by23.77%
Maintainers
1
Weekly downloads
 
Created
Source

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:

{
  "/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:

{
  "/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:

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

Normal usage

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.

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

NameTypeDefaultDescription
publicPath *stringundefinedThe path to your public folder (eg: "web")
manifestFilePath *stringundefinedThe filePath to your mix-manifest.json
(eg: "web/mix-manifest.json")
blackliststring/arrayundefinedA glob pattern of files to ignore re-hashing
keepBlacklistedEntriesbooleanfalseWhether to keep blacklisted entries in the manifest
delOptionsobject{ force: false }Options to provide to del - See options
debugbooleanfalseDebug exactly what's happening (or meant to happen) during runtime

* = Required

Full config example

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
        });
  })

This script was created for the Agency Webpack Mix Config.

Keywords

FAQs

Package last updated on 01 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc