I want to use mix on a set of images. First I copy them:
mix.copy('resources/images', 'public/images');
Then version:
mix.version();
The above does nothing to the images.
I've also tried specifying the path:
mix.version('public/images/*');
But I get a no such file or directory error.
How can I version the images?
version()
(without arguments) is not applied to files passed tocopy()
andcopyDirectory()
.If you'll look at the source of
mix.version
you'll see that it expands glob synchronously. But alllaravel-mix
operations such ascopy
andversion
are executed asynchronously. This means thatpublic/images/*
is empty because there are no files yet inpublic
directory.As a workaround you can list files in source directory (from which you copy files, for example
resources
), replaceresources
path segment withpublic
and pass this list toversion()
.In my case I have various assets in
resources
directory so directory tree looks like:I need to copy to
public
and version all these directories exceptless
which I need to preprocess and also version.This is like my
webpack.mix.js
looks like:Basically I use
glob
to recursively get a list of all files in each copied directory, replaceresources
withpublic
in their paths and then pass list of all such files tomix.version
.