João Serra
João Serra

Reputation: 519

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

Upvotes: 4

Views: 9483

Answers (2)

Sonal
Sonal

Reputation: 425

You can also use copyDirectory function, if you want to maintain the directory structure.

mix.copyDirectory('resources/assets/fonts', 'public/fonts');

Upvotes: 5

João Serra
João Serra

Reputation: 519

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

Upvotes: 9

Related Questions