copy-file-plugin
Version:
copy file plugin for webpack
136 lines (108 loc) • 2.96 kB
Markdown
<div align="center">
<h1>Copy File Webpack Plugin</h1>
<p>Copies individual files or entire directories to the build directory</p>
<p>Nodejs >= 8.5</p>
</div>
<h2 align="center">Install</h2>
```bash
npm i -D copy-file-plugin
```
<h2 align="center">Usage</h2>
**webpack.config.js**
```js
const CopyFilePlugin = require('copy-file-plugin')
const config = {
plugins: [
new CopyFilePlugin([ ...patterns ], options)
]
}
```
### `Patterns`
A simple pattern looks like this
```js
{ from: 'source', to: 'dest' }
```
Or, in case of just a `from` with the default destination, you can also use a `{String}` as shorthand instead of an `{Object}`
```js
'source'
```
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|[`from`](#from)|String|undefined|Globs accept [minimatch options](https://github.com/isaacs/minimatch)|
|[`to`](#to)|String|undefined|Output root if `from` is file or dir, resolved glob path if `from` is glob|
|[`test`](#test)|RegExp| |Pattern for extracting elements to be used in `to` templates|
|[`ignore`](#ignore)|Array|[]|Globs to ignore for this pattern|
|[`transform`](#transform)|Function|`(content, fromPath, toPath) => content`|Function or Promise that modifies file contents before copying|
|[`before`](#before)|Function|`(fromPath, toPath)`|Function or Promise that modifies file contents before transform|
|[`after`](#after)|Function|`(fromPath, toPath)`|Function or Promise that modifies file contents after transform|
|[`context`](#context)|String|`options.context` or `compiler.options.context`|A path that determines how to interpret the `from` path|
### `from, to`
**webpack.config.js**
```js
[
new CopyFilePlugin([
{ from: '**/*', to: 'relative/path/to/dest/' },
{ from: '**/*', to: '/absolute/path/to/dest/' }
], options)
]
```
### `ignore`
**webpack.config.js**
```js
[
new CopyFilePlugin([
{ from: 'src/**/*', to: 'dest/', ignore: [ '*.js' ] }
], options)
]
```
### `transform`
#### `{Function}`
**webpack.config.js**
```js
[
new CopyFilePlugin([
{
from: 'src/*.png',
to: 'dest/',
transform (content, path) {
return optimize(content)
}
}
], options)
]
```
### `context`
**webpack.config.js**
```js
[
new CopyFilePlugin([
{ from: 'src/*.txt', to: 'dest/', context: 'app/' }
], options)
]
```
<h2 align="center">Options</h2>
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|[`ignore`](#ignore)|Array|[]|Array of globs to ignore (applied to `from`)|
|[`context`](#context)|String|`compiler.options.context`|A path that determines how to interpret the `from` path, shared for all patterns|
|[`debug`](#debug)|Boolen|false|Debug mode|
### `ignore`
**webpack.config.js**
```js
[
new CopyFilePlugin(
[ ...patterns ],
{ ignore: [ '*.js', '*.css' ] }
)
]
```
### `context`
**webpack.config.js**
```js
[
new CopyFilePlugin(
[ ...patterns ],
{ context: [ '/app' ] }
)
]
```