There might be times when, as part of your build, you need to copy one or more files from one location to another. Mix's copy()
command makes this a cinch.
mix.copy('node_modules/foo/bar.css', 'public/css');
mix.copy([
'src/foo/one.css',
'src/bar/two.css'
], 'public/css');
A common usecase for this is when you wish to move a set of fonts, installed through NPM, to your public directory.
mix.copy('node_modules/vendor/fonts', 'public');
If it provides more clarity, mix.copyDirectory()
is an alias for mix.copy()
. The following is identical to the previous example.
mix.copyDirectory('node_modules/vendor/fonts', 'public');
Please note that, when providing a directory path as the first argument, the output will retain the original directory structure. If you wish to "flatten" it, provide a wildcard search.
mix.copyDirectory('path/to/dir/**', 'public/output');
mix.copy('vendor/lib/tests/**/*.php', 'tests');
mix.copy('tests/**/!(*.js)', 'public/foo');
The above will copy all files except for those that end in .js
.