Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't copy folders with Laravel Mix

i have a project using Laravel 5.4 and Laravel Mix, and i have an images folder where some of the images have the same name but a different category, as such they are contained within a diferent directory.

So

resources/
  assets/
    images/
      globalimage.png
      versiona/
        image1.png
        image2.png
      versionb/
        image1.png
        image2.png

What i need is the copy command in Laravel Mix to copy these folders as well as any files within them so that my public folder has the same folder structure.

How can i do this?

mix.js('resources/assets/backend/js/main.js', 'public/backend/js')
   .js('resources/assets/frontend/js/main.js', 'public/frontend/js')
   .sass('resources/assets/backend/sass/main.scss', 'public/backend/css')
   .sass('resources/assets/frontend/sass/main.scss', 'public/frontend/css')
   .sourceMaps()
   .copy( 'resources/assets/backend/images/**/*', 'public/backend/images/' )
   .copy( 'resources/assets/frontend/images/**/*', 'public/frontend/images/' )
   .version()
   .disableNotifications();

This is my current Mix config file the part i need to change is those copy commands

like image 213
João Serra Avatar asked Oct 18 '25 14:10

João Serra


1 Answers

Figured it out, there's a third parameter to the copy command which is a boolean which specifies whether or not to flatten the folder structure, if you set it to false it'll copy everything with it's folder structure intact.

So my Mix config became

   .copy( 'resources/assets/backend/images/', 'public/backend/images/' )
   .copy( 'resources/assets/frontend/images/', 'public/frontend/images/', false )

And that worked just fine

like image 118
João Serra Avatar answered Oct 21 '25 03:10

João Serra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!