Using the following code in the webpack.mix.js file webpack.mix.js try to copy all the files, directories and subdirectories from bower_components/strike-pro-frontend to public/ .

 // Copy frontend public folders mix.copy('bower_components/strike-pro-frontend/css/**/*', 'public/css'); mix.copy('bower_components/strike-pro-frontend/fonts/**/*', 'public/fonts'); mix.copy('bower_components/strike-pro-frontend/images/**/*', 'public/images'); mix.copy('bower_components/strike-pro-frontend/img/**/*', 'public/img'); mix.copy('bower_components/strike-pro-frontend/js/**/*', 'public/js'); 

Actually, the directory structure is evident:

enter image description here

But, when copying, the directory structure is ignored, and not all files are copied, but only those that are masked **/* .

Plus, in the end, all copied files are placed in one directory.

enter image description here

How do I copy files, directories and subdirectories to preserve the structure? Perhaps you should use a mask of another kind?

PS There are a lot of such directories in the project; it is not an option to prescribe separately mix.copy() for each group of subdirectories.

    1 answer 1

    Solution found!

    In order to preserve the structure of the copied directories, it was necessary to pass the third parameter to the mix.copy() function.

    According to the signature of the function mix.copy(from,to,flatten) - the 3rd flatten parameter defaults to true , i.e. all copied files from directories and from subdirectories will be copied to the to directory without saving the directory structure.

    In my case, the solution looks like this:

     mix.copy('bower_components/strike-pro-frontend/css', 'public/css', false); mix.copy('bower_components/strike-pro-frontend/fonts', 'public/fonts', false); mix.copy('bower_components/strike-pro-frontend/images', 'public/images', false); mix.copy('bower_components/strike-pro-frontend/img', 'public/img', false); mix.copy('bower_components/strike-pro-frontend/js', 'public/js', false); 

    Sources: