|
1 | 1 | # Copying Files
|
2 | 2 |
|
| 3 | + |
| 4 | +- [Basic Usage](#basic-usage) |
| 5 | + - [Copy a Single File](#copy-a-single-file) |
| 6 | + - [Copy Multiple Files](#copy-multiple-files) |
| 7 | + - [Copy a Directory](#copy-a-directory) |
| 8 | + - [Copy Files With the Given Extension](#copy-files-with-the-given-extension) |
| 9 | + - [Exclude an Extension From Being Copied](#exclude-an-extension-from-being-copied) |
| 10 | + |
| 11 | +### Basic Usage |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +#### Copy a Single File |
| 16 | + |
| 17 | +```js |
| 18 | +mix.copy('node_modules/foo/bar.css', 'public/css'); |
| 19 | +``` |
| 20 | + |
| 21 | +#### Copy Multiple Files |
| 22 | + |
| 23 | +```js |
| 24 | +mix.copy([ |
| 25 | + 'src/foo/one.css', |
| 26 | + 'src/bar/two.css' |
| 27 | +], 'public/css'); |
| 28 | +``` |
| 29 | + |
| 30 | +#### Copy a Directory |
| 31 | + |
| 32 | +A common usecase for this is when you wish to move a set of fonts, installed through NPM, to your public directory. |
| 33 | + |
| 34 | +```js |
| 35 | +mix.copy('node_modules/vendor/fonts', 'public'); |
| 36 | +``` |
| 37 | + |
| 38 | +If it provides more clarity, `mix.copyDirectory()` is an alias for `mix.copy()`. The following is identical to the previous example. |
| 39 | + |
| 40 | +```js |
| 41 | +mix.copyDirectory('node_modules/vendor/fonts', 'public'); |
| 42 | +``` |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +```js |
| 47 | +mix.copyDirectory('path/to/dir/**', 'public/output'); |
| 48 | +``` |
| 49 | + |
| 50 | +#### Copy Files With the Given Extension |
| 51 | + |
3 | 52 | ```js
|
4 |
| -mix.copy(from, to); |
5 |
| -mix.copy('from/regex/**/*.txt', to); |
6 |
| -mix.copy([path1, path2], to); |
7 |
| -mix.copyDirectory(fromDir, toDir); |
| 53 | +mix.copy('vendor/lib/tests/**/*.php', 'tests'); |
8 | 54 | ```
|
9 | 55 |
|
10 |
| -From time to time, you'll want to copy one or more files, as part of your build process. No problem; that's a cinch. Use the mix.copy\(\) method to specify the source file or folder, and then your desired destination. |
| 56 | +#### Exclude an Extension From Being Copied |
11 | 57 |
|
12 | 58 | ```js
|
13 |
| -mix.copy('node_modules/vendor/acme.txt', 'public/js/acme.txt'); |
| 59 | +mix.copy('tests/**/!(*.js)', 'public/foo'); |
14 | 60 | ```
|
15 | 61 |
|
16 |
| -Upon compilation, the "acme" file will be copied to `public/js/acme.txt`, accordingly. A common use case for this is when you wish to move a set of fonts, installed through NPM, to your public directory. |
| 62 | +The above will copy all files except for those that end in `.js`. |
0 commit comments