Copy File Webpack Plugin
Copies individual files or entire directories to the build directory
Nodejs >= 8.5
Install
npm i -D copy-file-plugin
Usage
webpack.config.js
const CopyFilePlugin = const config = plugins: ...patterns options
Patterns
A simple pattern looks like this
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}
'source'
Name | Type | Default | Description |
---|---|---|---|
from |
String | undefined | Globs accept minimatch options |
to |
String | undefined | Output root if from is file or dir, resolved glob path if from is glob |
test |
RegExp | Pattern for extracting elements to be used in to templates |
|
ignore |
Array | [] | Globs to ignore for this pattern |
transform |
Function | (content, fromPath, toPath) => content |
Function or Promise that modifies file contents before copying |
before |
Function | (fromPath, toPath) |
Function or Promise that modifies file contents before transform |
after |
Function | (fromPath, toPath) |
Function or Promise that modifies file contents after transform |
context |
String | options.context or compiler.options.context |
A path that determines how to interpret the from path |
from, to
webpack.config.js
from: '**/*' to: 'relative/path/to/dest/' from: '**/*' to: '/absolute/path/to/dest/' options
ignore
webpack.config.js
from: 'src/**/*' to: 'dest/' ignore: '*.js' options
transform
{Function}
webpack.config.js
from: 'src/*.png' to: 'dest/' { return } options
context
webpack.config.js
from: 'src/*.txt' to: 'dest/' context: 'app/' options
Options
Name | Type | Default | Description |
---|---|---|---|
ignore |
Array | [] | Array of globs to ignore (applied to from ) |
context |
String | compiler.options.context |
A path that determines how to interpret the from path, shared for all patterns |
debug |
Boolen | false | Debug mode |
ignore
webpack.config.js
...patterns ignore: '*.js' '*.css'
context
webpack.config.js
...patterns context: '/app'