Would be easier to use cachebuster plugin instead. Essentially does the same as what your trying to do.
I do not think there is a way to pickup on the package file version number. You might be able to go the other way, by using a Git commit hook to alter the var value in the config file. A bash script might be an option too.
@texnixe Nice work! But doesn’t that depend on where the package.json is in the file system? The reason i didnt think this possible is because generally this file is outside of the web root. Looking at @francoisromain attempt, his climbing up a few levels to reach the file. I think thats the problem?
Ok, but I don’t think that will work on my setup, because using vagrant (and i’m guessing this will be the case with MAMP), you map a folder that gets shared inside the virtual machine. Usually you map the webroot (usually called public or www etc).
Because the package.json is outside this shared folder, it wont be seen. As far as the Vagrant filesystem is concerned, it doesnt exist.
Depending on what setup @francoisromain is using, he may have to adjust the folder sharing a level up in order for the file to be accessible.
this works perfectly locally (on Mamp) and remotely on Gandi simple hosting. Thank you!
And thanks @jimbobrjames for the cachebuster plugin. I didn’t know about it yet.