根据规则复制文件,支持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 ismatched 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 lookupsthe specified name via "require()".-u, --update The flag to not overwrite files on destination ifthe 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 copythe file to <dest> every changing.
cpx "src/**/*.{html,png,jpg}" app --watch
从src
文件夹拷贝 html/png/jpg 文件到 app 目录。保持文件结构。当文件改变时,复制他们。