copy-file-plugin

1.0.4 • Public • Published

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 = require('copy-file-plugin')
 
const config = {
  plugins: [
    new CopyFilePlugin([ ...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

[
  new CopyFilePlugin([
    { from: '**/*', to: 'relative/path/to/dest/' },
    { from: '**/*', to: '/absolute/path/to/dest/' }
  ], options)
]

ignore

webpack.config.js

[
  new CopyFilePlugin([
    { from: 'src/**/*', to: 'dest/', ignore: [ '*.js' ] }
  ], options)
]

transform

{Function}

webpack.config.js

[
  new CopyFilePlugin([
    {
      from: 'src/*.png',
      to: 'dest/',
      transform (content, path) {
        return optimize(content)
      }
    }
  ], options)
]

context

webpack.config.js

[
  new CopyFilePlugin([
    { 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

[
  new CopyFilePlugin(
    [ ...patterns ],
    { ignore: [ '*.js', '*.css' ] }
  )
]

context

webpack.config.js

[
  new CopyFilePlugin(
    [ ...patterns ],
    { context: [ '/app' ] }
  )
]

Package Sidebar

Install

npm i copy-file-plugin

Weekly Downloads

8

Version

1.0.4

License

MIT

Unpacked Size

5.2 kB

Total Files

3

Last publish

Collaborators

  • jsxio