Code Monkey home page Code Monkey logo

copy-webpack-plugin's Introduction

Copy Webpack Plugin

This is a webpack plugin that copies individual files or entire directories to the build directory.

Getting started

Install the plugin:

npm install --save-dev copy-webpack-plugin

Usage

new CopyWebpackPlugin([patterns], options)

A pattern looks like: { from: 'source', to: 'dest' }

Pattern properties:

  • from
    • is required
    • can be an absolute or path relative to the context
    • can be a file or directory
    • can be a glob
  • to
    • is optional
    • if not absolute, it's relative to the build root
    • must be a directory if from is a directory
  • toType
    • is optional
    • is ignored if from is a directory
    • defaults to 'file' if to has an extension
    • defaults to 'dir' if to doesn't have an extension
  • force
    • is optional
    • defaults to false
    • forces the plugin to overwrite files staged by previous plugins

Available options:

  • ignore
    • an array of files and directories to ignore
    • accepts globs
    • globs are evaluated on the from path, relative to the context

Examples

var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');

module.exports = {
    context: path.join(__dirname, 'app'),
    plugins: [
        new CopyWebpackPlugin([
            // {output}/file.txt
            { from: 'from/file.txt' },
            
            // {output}/to/file.txt
            { from: 'from/file.txt', to: 'to/file.txt' },
            
            // {output}/to/directory/file.txt
            { from: 'from/file.txt', to: 'to/directory' },

            // Copy directory contents to {output}/
            { from: 'from/directory' },
            
            // Copy directory contents to {output}/to/directory/
            { from: 'from/directory', to: 'to/directory' },
            
            // Copy glob results to /absolute/path/
            { from: 'from/directory/**/*', to: '/absolute/path' },
            
            // {output}/file/without/extension
            {
                from: 'path/to/file.txt',
                to: 'file/without/extension',
                toType: 'file'
            },
            
            // {output}/directory/with/extension.ext/file.txt
            {
                from: 'path/to/file.txt',
                to: 'directory/with/extension.ext',
                toType: 'dir'
            }
        ], {
            ignore: [
                // Doesn't copy any files with a txt extension    
                '*.txt',
                
                // Doesn't copy any file, even if they start with a dot
                { glob: '**/*', dot: true }
            ]
        })
    ]
};

Testing

Build Status

Run npm test

License

MIT

copy-webpack-plugin's People

Contributors

kevlened avatar mgcrea avatar matus-m avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.