Laravel Mix plugin that replaces all the assets URLs with the corresponding hashed one generated by version().
This plugin is mainly meant to be used in a CI/CD workflow.
npm i laravel-mix-version-apply
let mix = require('laravel-mix');
require('laravel-mix-version-apply');
mix
.setPublicPath('.')
.sass('src/app.scss', 'dist/')
.js('src/app.js', 'dist/');
if (mix.inProduction()) {
mix
.version()
.versionApply(['index.html']);
}
With fileInput you can specificy the files in which you want to replace the assets URL. Supported formats are:
- Array of strings
- Glob string
- Single string
Before versionApply():
<!DOCTYPE html>
<html lang="en">
<head>
<title>Laravel Mix Version Apply Plugin</title>
<link rel="stylesheet" href="/dist/app.css">
</head>
<body>
<h1>Laravel Mix Version Apply Plugin</h1>
<script src="/dist/app.js"></script>
</body>
</html>
After versionApply():
<!DOCTYPE html>
<html lang="en">
<head>
<title>Laravel Mix Version Apply Plugin</title>
<link rel="stylesheet" href="/dist/app.css?id=082fcf4a96cc981bfab1">
</head>
<body>
<h1>Laravel Mix Version Apply Plugin</h1>
<script src="/dist/app.js?id=b5a3764d979b90fe8dd7"></script>
</body>
</html>