You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[`from`](#from)|`{String\|Object}`|`undefined`|Globs accept [minimatch options](https://github.com/isaacs/minimatch). See the [`node-glob` options](https://github.com/isaacs/node-glob#options) in addition to the ones below.|
64
-
|[`to`](#to)|`{String\|Object}`|`undefined`| Output root if `from` is file or dir, resolved glob path if `from` is glob. |
|[`test`](#test)|`{RegExp}`|`undefined`|Pattern for extracting elements to be used in `to`templates. |
67
-
|[`force`](#force)|`{Boolean}`|`false`| Overwrites files already in `compilation.assets` (usually added by other plugins/loaders). |
68
-
|[`ignore`](#ignore)|`{Array}`|`[]`| Globs to ignore for this pattern. |
69
-
|[`flatten`](#flatten)|`{Boolean}`|`false`| Removes all directory references and only copies file names.⚠️ If files have the same name, the result is non-deterministic.|
70
-
|[`transform`](#transform)|`{Function\|Promise}`|`(content, path) => content`| Function or Promise that modifies file contents before copying.|
71
-
|[`transformPath`](#transformPath)|`{Function\|Promise}`|`(targetPath, sourcePath) => path`| Function or Promise that modifies file writing path.|
72
-
|[`cache`](#cache)|`{Boolean\|Object}`|`false`| Enable `transform` caching. You can use `{ cache: { key: 'my-cache-key' } }` to invalidate the cache. |
73
-
|[`context`](#context)|`{String}`|`options.context \|\| compiler.options.context`| A path that determines how to interpret the `from` path.|
|[`context`](#context)|`{String}`|`options.context \|\| compiler.options.context`| A path that determines how to interpret the `from` path.|
66
+
|[`toType`](#toType)|`{String}`|`undefined`|Determinate what is `to`option - directory, file or template.|
67
+
|[`test`](#test)|`{RegExp}`|`undefined`| Pattern for extracting elements to be used in `to` templates.|
68
+
|[`force`](#force)|`{Boolean}`|`false`| Overwrites files already in `compilation.assets` (usually added by other plugins/loaders).|
69
+
|[`ignore`](#ignore)|`{Array}`|`[]`| Globs to ignore files. |
70
+
|[`flatten`](#flatten)|`{Boolean}`|`false`| Removes all directory references and only copies file names.|
71
+
|[`transform`](#transform)|`{Function\|Promise}`|`undefined`| Allows to modify the file contents.|
72
+
|[`cache`](#cache)|`{Boolean\|Object}`|`false`| Enable `transform` caching. You can use `{ cache: { key: 'my-cache-key' } }` to invalidate the cache. |
73
+
|[`transformPath`](#transformPath)|`{Function\|Promise}`|`undefined`| Allows to modify the writing path.|
You can defined `from` as `Object` and use the [`node-glob` options](https://github.com/isaacs/node-glob#options).
84
+
85
+
> ⚠️ Don't use directly `\\` in `from` (i.e `path\to\file.ext`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
86
+
> On Windows, the forward slash and the backward slash are both separators.
87
+
> Instead please use `/` or `path` methods.
88
+
77
89
**webpack.config.js**
78
90
79
91
```js
@@ -93,6 +105,15 @@ module.exports = {
93
105
94
106
#### `to`
95
107
108
+
Type: `String`
109
+
Default: `undefined`
110
+
111
+
Output path.
112
+
113
+
> ⚠️ Don't use directly `\\` in `to` (i.e `path\to\dest`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
114
+
> On Windows, the forward slash and the backward slash are both separators.
A path that determines how to interpret the `from` path.
136
+
137
+
> ⚠️ Don't use directly `\\` in `context` (i.e `path\to\context`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
138
+
> On Windows, the forward slash and the backward slash are both separators.
139
+
> Instead please use `/` or `path` methods.
140
+
141
+
**webpack.config.js**
142
+
143
+
```js
144
+
module.exports= {
145
+
plugins: [
146
+
newCopyPlugin([
147
+
{
148
+
from:'src/*.txt',
149
+
to:'dest/',
150
+
context:'app/',
151
+
},
152
+
]),
153
+
],
154
+
};
155
+
```
156
+
109
157
#### `toType`
110
158
159
+
Type: `String`
160
+
Default: `undefined`
161
+
162
+
Determinate what is `to` option - directory, file or template.
163
+
Sometimes it is hard to say what is `to`, example `path/to/dir-with.ext`.
164
+
If you want to copy files in directory you need use `dir` option.
165
+
We try to automatically determine the `type` so you most likely do not need this option.
|**`'dir'`**|`{String}`|`undefined`| If `from` is directory, `to` has no extension or ends in `'/'`|
@@ -170,6 +226,11 @@ module.exports = {
170
226
171
227
#### `test`
172
228
229
+
Type: `RegExp`
230
+
Default: `undefined`
231
+
232
+
Pattern for extracting elements to be used in `to` templates.
233
+
173
234
Defines a `{RegExp}` to match some parts of the file path.
174
235
These capture groups can be reused in the name property using `[N]` placeholder.
175
236
Note that `[0]` will be replaced by the entire path of the file,
@@ -194,6 +255,11 @@ module.exports = {
194
255
195
256
#### `force`
196
257
258
+
Type: `Boolean`
259
+
Default: `false`
260
+
261
+
Overwrites files already in `compilation.assets` (usually added by other plugins/loaders).
262
+
197
263
**webpack.config.js**
198
264
199
265
```js
@@ -212,6 +278,11 @@ module.exports = {
212
278
213
279
#### `ignore`
214
280
281
+
Type: `Array`
282
+
Default: `[]`
283
+
284
+
Globs to ignore files.
285
+
215
286
**webpack.config.js**
216
287
217
288
```js
@@ -230,6 +301,13 @@ module.exports = {
230
301
231
302
#### `flatten`
232
303
304
+
Type: `Boolean`
305
+
Default: `false`
306
+
307
+
Removes all directory references and only copies file names.
308
+
309
+
> ⚠️ If files have the same name, the result is non-deterministic.
310
+
233
311
**webpack.config.js**
234
312
235
313
```js
@@ -248,6 +326,11 @@ module.exports = {
248
326
249
327
#### `transform`
250
328
329
+
Type: `Function|Promise`
330
+
Default: `undefined`
331
+
332
+
Allows to modify the file contents.
333
+
251
334
##### `{Function}`
252
335
253
336
**webpack.config.js**
@@ -288,9 +371,13 @@ module.exports = {
288
371
};
289
372
```
290
373
291
-
#### `transformPath`
374
+
#### `cache`
292
375
293
-
##### `{Function}`
376
+
Type: `Boolean|Object`
377
+
Default: `false`
378
+
379
+
Enable/disable `transform` caching. You can use `{ cache: { key: 'my-cache-key' } }` to invalidate the cache.
380
+
Default path to cache directory: `node_modules/.cache/copy-webpack-plugin`.
294
381
295
382
**webpack.config.js**
296
383
@@ -301,36 +388,28 @@ module.exports = {
301
388
{
302
389
from:'src/*.png',
303
390
to:'dest/',
304
-
transformPath(targetPath, absolutePath) {
305
-
return'newPath';
391
+
transform(content, path) {
392
+
returnoptimize(content);
306
393
},
394
+
cache:true,
307
395
},
308
396
]),
309
397
],
310
398
};
311
399
```
312
400
313
-
##### `{Promise}`
401
+
####`transformPath`
314
402
315
-
**webpack.config.js**
403
+
Type: `Function|Promise`
404
+
Default: `undefined`
316
405
317
-
```js
318
-
module.exports= {
319
-
plugins: [
320
-
newCopyPlugin([
321
-
{
322
-
from:'src/*.png',
323
-
to:'dest/',
324
-
transformPath(targePath, absolutePath) {
325
-
returnPromise.resolve('newPath');
326
-
},
327
-
},
328
-
]),
329
-
],
330
-
};
331
-
```
406
+
Allows to modify the writing path.
332
407
333
-
#### `cache`
408
+
> ⚠️ Don't return directly `\\` in `transformPath` (i.e `path\to\newFile`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
409
+
> On Windows, the forward slash and the backward slash are both separators.
410
+
> Instead please use `/` or `path` methods.
411
+
412
+
##### `{Function}`
334
413
335
414
**webpack.config.js**
336
415
@@ -341,17 +420,16 @@ module.exports = {
341
420
{
342
421
from:'src/*.png',
343
422
to:'dest/',
344
-
transform(content, path) {
345
-
returnoptimize(content);
423
+
transformPath(targetPath, absolutePath) {
424
+
return'newPath';
346
425
},
347
-
cache:true,
348
426
},
349
427
]),
350
428
],
351
429
};
352
430
```
353
431
354
-
####`context`
432
+
##### `{Promise}`
355
433
356
434
**webpack.config.js**
357
435
@@ -360,9 +438,11 @@ module.exports = {
360
438
plugins: [
361
439
newCopyPlugin([
362
440
{
363
-
from:'src/*.txt',
441
+
from:'src/*.png',
364
442
to:'dest/',
365
-
context:'app/',
443
+
transformPath(targePath, absolutePath) {
444
+
returnPromise.resolve('newPath');
445
+
},
366
446
},
367
447
]),
368
448
],
@@ -404,6 +484,8 @@ module.exports = {
404
484
405
485
#### `ignore`
406
486
487
+
Array of globs to ignore (applied to `from`).
488
+
407
489
**webpack.config.js**
408
490
409
491
```js
@@ -414,6 +496,8 @@ module.exports = {
414
496
415
497
#### `context`
416
498
499
+
A path that determines how to interpret the `from` path, shared for all patterns.
500
+
417
501
**webpack.config.js**
418
502
419
503
```js
@@ -424,6 +508,8 @@ module.exports = {
424
508
425
509
#### `copyUnmodified`
426
510
511
+
Copies files, regardless of modification when using watch or `webpack-dev-server`. All files are copied on first build, regardless of this option.
512
+
427
513
> ℹ️ By default, we only copy **modified** files during a `webpack --watch` or `webpack-dev-server` build. Setting this option to `true` will copy all files.
0 commit comments