>ℹ️Ifyouwant`webpack-dev-server` to write files to the output directory during development, you can force it with the [`writeToDisk`](https://github.com/webpack/webpack-dev-middleware#writetodisk) option or the [`write-file-webpack-plugin`](https://github.com/gajus/write-file-webpack-plugin).
>⚠️Don'tusedirectly`\\` in `from` option if it is a `glob` (i.e `path\to\file.ext`)optionbecauseonUNIXthebackslashisavalidcharacterinsideapathcomponent,i.e.,it'snotaseparator.
>⚠️Don'tusedirectly`\\` in `context` (i.e `path\to\context`)optionbecauseonUNIXthebackslashisavalidcharacterinsideapathcomponent,i.e.,it'snotaseparator.
The`context` option can be an absolute or relative path. If `context` is a relative, then it is converted to absolute based to `compiler.options.context`
If`from` is a file, then `context`isequaltothedirectoryinwhichthisfileislocated.Accordingly,theresultwillbeonlythefilename.
If`from` is a directory, then `context` is the same as `from`andisequaltothedirectoryitself.Inthiscase,theresultwillbeahierarchicalstructureofthefoundfoldersandfilesrelativetothespecifieddirectory.
If`from` is a glob, then regardless of the `context` option, the result will be the structure specified in the `from`option
// The `content` argument is a [`Buffer`](https://nodejs.org/api/buffer.html) object, it could be converted to a `String` to be processed using `content.toString()`
// The `absoluteFrom` argument is a `String`, it is absolute path from where the file is being copied
// The `content` argument is a [`Buffer`](https://nodejs.org/api/buffer.html) object, it could be converted to a `String` to be processed using `content.toString()`
// The `absoluteFrom` argument is a `String`, it is absolute path from where the file is being copied
>ℹ️The`to` option must be specified and point to a file. It is allowed to use only `[contenthash]` and `[fullhash]`templatestrings.
**webpack.config.js**
```js
module.exports={
plugins:[
newCopyPlugin({
patterns:[
{
from:"src/**/*.txt",
to:"dest/file.txt",
// The `assets` argument is an assets array for the pattern.from ("src/**/*.txt")
transformAll(assets){
constresult=assets.reduce((accumulator,asset)=>{
// The asset content can be obtained from `asset.source` using `source` method.
// The asset content is a [`Buffer`](https://nodejs.org/api/buffer.html) object, it could be converted to a `String` to be processed using `content.toString()`
constcontent=asset.data;
accumulator=`${accumulator}${content}\n`;
returnaccumulator;
},"");
returnresult;
},
},
],
}),
],
};
```
###`noErrorOnMissing`
Type:
```ts
typenoErrorOnMissing=boolean;
```
Default:`false`
Doesn'tgenerateanerroronmissingfile(s).
```js
module.exports={
plugins:[
newCopyPlugin({
patterns:[
{
from:path.resolve(__dirname,"missing-file.txt"),
noErrorOnMissing:true,
},
],
}),
],
};
```
####`info`
Type:
```ts
typeinfo=
|Record<string,any>
|((item:{
absoluteFilename:string;
sourceFilename:string;
filename:string;
toType:ToType;
})=>Record<string,any>);
```
Default:`undefined`
Allowstoaddassetsinfo.
**webpack.config.js**
```js
module.exports={
plugins:[
newCopyPlugin({
patterns:[
"relative/path/to/file.ext",
{
from:"**/*",
// Terser skip this file for minimization
info:{minimized:true},
},
],
}),
],
};
```
**webpack.config.js**
```js
module.exports={
plugins:[
newCopyPlugin({
patterns:[
"relative/path/to/file.ext",
{
from:"**/*",
// Terser skip this file for minimization
info:(file)=>({minimized:true}),
},
],
}),
],
};
```
###Options
-[`concurrency`](#concurrency)
####`concurrency`
type:
```ts
typeconcurrency=number;
```
default:`100`
limitsthenumberofsimultaneousrequeststofs
**webpack.config.js**
```js
module.exports={
plugins:[
newCopyPlugin({
patterns:[...patterns],
options:{concurrency:50},
}),
],
};
```
###Examples
####Differentvariants`from` (`glob`, `file` or `dir`).
Ifyouwantonlycontent`src/directory-nested/`, you should only indicate `glob` in `from`. The path to the folder in which the search should take place, should be moved to `context`.