密码
复制文件 globs, 监视更改 .
这个模块提供了类似 CLI 的工具 cp但用观察.
安装
npm install cpx
- 需要节点.js
>=6.5。 。 。 .
使用量
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.
示例
$ cpx "src/**/*.{html,png,jpg}" app --watch
此示例将复制 html/png/jpg 文件 src 目录到 app
目录,保留文件树结构.
每次文件被更改时,请复制.
由于巴什会膨胀出"光"字,需要用"双引"来附加.
你们可以一起用 浏览器。 。 。 .
$ cpx "src/**/*.{html,png,jpg}" app -w & watchify src/index.js -o app/index.js
您可以使用 shell 命令转换每个文件 .
$ cpx "src/**/*.js" app -w -c "babel --source-maps inline"
您可以使用变换包来浏览 .
$ cpx "src/**/*.js" app -w -t babelify -t uglifyify
它也许可以用来添加页眉注释,优化图像,或者...
节点.js API
您可以使用这个模块作为节点模块.
var cpx = require("cpx");
cpx. 副本
cpx.copy(source, dest, options, callback)
cpx.copy(source, dest, callback)
- 来源
{string}- 一个复制目标的文件. - 离线
{string}-- 目的地目录的文件路径. - 选项
{object}- 选项。清除
{boolean}- 说吧 要删除在复制前复制过的文件的旗帜 。 默认 :false。 。 。 . - 选项
{boolean}- 说吧 复制时要遵循符号链接的旗帜 。 默认 :false。 。 。 . - 选项。包括EmptyDirs
{boolean}- 说吧 复制与 glob 匹配的空目录的旗帜 。 默认 :false。 。 。 . - 选项
{boolean}- 旗子在观看初期不复制. 这是给cpx.watch()默认 :true。 。 。 . - 选项。保留
{boolean}-- 复制 uid, gid, atime, 和 mtime 文件的旗帜. 默认 :false。 。 。 . - 选项
{((filepath: string) => stream.Transform)[]}-- 创建stream.Transform对象可转换每个复制文件. - 选项更新
{boolean}- 说吧 如果源文件年龄较大, 则不覆盖目的地文件的旗帜 。 默认 :false。 。 。 .
- 选项。清除
- 回调
{(err: Error|null) => void}- 一个叫做完成的函数.
复制匹配的文件 source 缩写为 dest 目录.
cpx. 复制同步
cpx.copySync(source, dest, options)
cpx.copySync(source, dest)
同步函数 cpx.copy。 。 。 .
参数几乎与 cpx.copy。 。 。 .
不过 options.transform 不被支持.
cpx.watch (英语)
cpx.watch(source, dest, options)
cpx.watch(source, dest)
复制匹配的文件 source 缩写字符串为 dest 目录.
第一次复制后,开始观察. 并且每次更改时都会复制文件.
参数与 cpx.copy。 。 。 .
cpx.watch 返回一个 EventEmitter。 。 。 .
.on("copy", (e) => { ... }):文件复制后被解雇.e.srcPath是原始文件的路径.e.dstPath是新文件的路径 ..on("remove", (e) => { ... }): 删除文件后被解雇.e.path是已删除文件的路径 ..on("watch-ready", () => { ... }):在第一次复制后开始观看文件时被开除..on("watch-error", (err) => { ... }):在观看时发生错误时被开除.
更改日志
捐款
谢谢你的贡献!
错误报告或特性请求
请使用 GitHub 问题 .
文件更正
请使用 GitHub Pull 请求 . 我将特别感谢文件更正,因为我不熟悉英文.
特点 执行
请使用 GitHub Pull 请求 .
有一些 npm 标记来帮助发展.
npm test- 测试和收集覆盖.npm run build- 从 src 目录中创建 lib 目录 .npm run clean- 删除由其他命令创建的目录(文件夹).npm run lint- 运行ESLint.npm run watch- 在修改每个文件时进行测试(不收集覆盖).npm run open-coverage- 打开最后一个报告npm test使用网页浏览器命令.