← All tools

cpx

Popularity 65 Updated Development & Build

Copy file globs, watching for changes.

npmauto-collected

Installation

npm
npm install -g cpx

Install with npm.

cpx

Copy file globs, watching for changes.

This module provides a CLI tool like cp, but with watching.

Installation

npm install cpx
  • Requires Node.js =6.5.

Usage

Usage: cpx <source> <dest> [options]

    Copy files, watching for changes.

        <source>  The glob of target files.
        <dest>    The path of a destination directory.

Options:

    -c, --command <command>   A command text to transform each file.
    -C, --clean               Clean files that matches <source> like pattern in
                              <dest> directory before the first copying.

-h, --help Print usage information. --include-empty-dirs The flag to copy empty directories which is matched with the glob. --no-initial The flag to not copy at the initial time of watch. Use together '--watch' option. -p, --preserve The flag to copy attributes of files. This attributes are uid, gid, atime, and mtime. -t, --transform <name A module name to transform each file. cpx lookups the specified name via "require()". -u, --update The flag to not overwrite files on destination if the source file is older. -v, --verbose Print copied/removed files. -V, --version Print the version number. -w, --watch Watch for files that matches <source, and copy the file to <dest every changing.



## Example

$ cpx "src//.{html,png,jpg}" app --watch


This example will copy html/png/jpg files from `src` directory to `app`
directory, keeping file tree structure.
Whenever the files are changed, copy them.

> Since Bash expands globs, requires to enclose it with double quotes.

You can use together [Browserify](http://browserify.org).

$ cpx "src//.{html,png,jpg}" app -w & watchify src/index.js -o app/index.js


You can use shell commands to convert each file.

$ cpx "src//.js" app -w -c "babel --source-maps inline"


You can use the transform packages for Browserify.

$ cpx "src//.js" app -w -t babelify -t uglifyify


It maybe can use to add header comment, to optimize images, or etc...


## Node.js API

You can use this module as a node module.