dmsone97's avatar

Laravel Mix copy happening after compile of files (Laravel 5.4)

It seems like files that I am copying are being copied after the files are being transpiled.

mix.js('resources/assets/js/app.js', 'public/js/footer.js') 
.sass('resources/assets/sass/app.scss', 'public/css/')
mix.copy('vendor/zurb/foundation/js', 'resources/assets/js/foundation', false)    .copy('vendor/zurb/foundation', 'resources/assets/sass/foundation', false)
.version();

when I run this the first time I get errors like ./foundation/foundation.util.mediaQuery.js in ./resources/assets/js/foundation.js but when it run it again it works correctly no errors.

This leads me to believe that the .copy is happening after the compile (I assume this file is running asynchronously) and so the file are not found.

Is there a way to do the copy before all the other files are compiled or turn off async?

0 likes
2 replies
tomvo's avatar

I encounter this too, I want to copy resources from node_modules to my resources folder and then include them in sass but the copy runs after the .sass() command. Did you find a solution for this?

WebKenth's avatar

Just wondering why are you are using mix twice? I'd guess that each pipe does it thing first before continuing to the next in the chain so it should be:

mix.copy('vendor/zurb/foundation/js', 'resources/assets/js/foundation', false).copy('vendor/zurb/foundation', 'resources/assets/sass/foundation', false).js('resources/assets/js/app.js', 'public/js/footer.js').sass('resources/assets/sass/app.scss', 'public/css/').version();

Side note: Rather than copying ressources every single recompile why not just reference them?

@import "filelocation" or require('file.js');

Please or to participate in this conversation.