ben-rogerson / laravel-mix-make-file-hash Goto Github PK
View Code? Open in Web Editor NEW๐ Convert Laravel Mix querystring hashing to filename hashing. Eg: main.css?id=abcd1234 to main.abcd1234.css
License: MIT License
๐ Convert Laravel Mix querystring hashing to filename hashing. Eg: main.css?id=abcd1234 to main.abcd1234.css
License: MIT License
jsonFile.readFile
and jsonFile.writeFile
are asynchronous operations. I want to do some additional stuff after the manifest.json
file has been updated. Either a promise should be returned upon completion or failure, or the synchronous methods should be used.
I am using this package to make file names with hash.
but the problem is i want to upload files to S3 Server but your plugin runs after webpackconfig plugins!
here is my plugin apply method:
apply(compiler) {
compiler.plugin('after-emit', (compilation, cb) => {
this.validateOptions(compilation, cb)
this.getAssets(compilation)
.then(files => this.filterAllowedAssets(files))
.then(files => this.uploadAssets(files))
.then(() => this.filterAllowedDirectories())
.then(directories => this.uploadDirectories(directories))
.then(() => cb())
.catch(e => this.handleErrors(e, compilation, cb));
});
}
Hi Ben!
Thanks for creating this, I needed a replacement for laravel-mix-versionhash. Gonna check out your Agency set up soon.
I'm not able to delete the stale hashed files with force set to true in delOptions. Here's the output with debug turned on:
Manifest found: '../web/dist/mix-manifest.json'
Renamed '../web/dist/js/app.js' to '../web/dist/js/app.b1e46e01a3c3a84c3cd6.js' (delOptions '{"force":true}')
Renamed '../web/dist/css/app.css' to '../web/dist/css/app.36b4410866e3e76ee304.css' (delOptions '{"force":true}')
Finished updating '../web/dist/mix-manifest.json' with the new filenames:
{
'/js/app.js': '/js/app.b1e46e01a3c3a84c3cd6.js',
'/css/app.css': '/css/app.36b4410866e3e76ee304.css'
}
The built files from previous runs are still there. Not a biggie but I'd like to nuke them.
The invocation:
if (mix.inProduction()) {
mix.version();
mix.then(() => {
convertToFileHash({
publicPath: '../web/dist',
manifestFilePath: '../web/dist/mix-manifest.json',
delOptions: { force: true },
debug: true
});
});
}
Here are the versions I'm using:
"devDependencies": {
"laravel-mix": "^6.0.11",
"laravel-mix-make-file-hash": "^2.2.0",
"laravel-mix-purgecss": "^6.0.0",
"postcss": "^8.2.4",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.5",
"sass-loader": "^8.0.2"
}
Please advise. Thanks!
USE CASE
: I want to rename only JS, CSS and image files, specifically not HTML files. I can create a pull request to add an option for this, unless you know of a better way to handle this use case directly in Laravel Mix?
I'm kind of new to Laravel Mix, but I think doing all accrodingly to the docs, all files inside of /images
folder has plain names, w\o\ hash being applied to them.
MY Mix config:
const convertToFileHash = require("laravel-mix-make-file-hash");
mix.setPublicPath('resources/dist');
mix.version().then(() => {
convertToFileHash({
publicPath: "resources/dist",
manifestFilePath: "resources/dist/mix-manifest.json"
});
});
HAs is successfully being added to CSS and JS files, and these changes also reflected in manifest json file. But I can't seem to make images work the same way. Please, advice!
When setting the resource root
i.e.
mix.setResourceRoot('public/assets');
The generate scss files do not use the hash for a respective image file.
The generated image filename:
2ndpg-hdr.0153009dd5cf3cc09e63.jpg
The resulting css style:
.someDiv { background-image: url(/public/assets/2ndpg-hdr.jpg?09845228d6032d2361194d24968b0c5c); }
As a result, images aren't displayed correctly
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.