cpx

根据规则复制文件,支持watch(当文件夹发生变化,同步复制)

安装

npm install cpx

使用

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.
-L, --dereference Follow symbolic links when copying from them.
-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

src文件夹拷贝 html/png/jpg 文件到 app 目录。保持文件结构。当文件改变时,复制他们。