@akryum/cpx

中文文档
1.5.3发布于 2021/07/30MITCommonJS近 30 天下载 1698

复制文件 globs, 监视更改 .

中文使用文档
文档目录12 节
  1. 安装
  2. 使用量
  3. 示例
  4. 节点.js API
  5. cpx. 副本
  6. cpx. 复制同步
  7. cpx.watch (英语)
  8. 更改日志
  9. 捐款
  10. 错误报告或特性请求
  11. 文件更正
  12. 特点 执行

密码

npm version Downloads/month Build Status codecov Dependency Status

复制文件 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 问题 .

文件更正

请使用 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 使用网页浏览器命令.

版本与发布记录

@akryum/cpx 共发布 3 个版本,首次发布于 2021/04/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.3latest2021/07/305 年前
1.5.22021/07/145 年前
1.5.12021/04/055 年前

关于 @akryum/cpx 的常见问题

@akryum/cpx 是什么?

复制文件 globs, 监视更改 .

如何安装 @akryum/cpx?

在项目目录运行 npm install @akryum/cpx,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cpx,可以用 npx cpx 直接运行。

@akryum/cpx 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/akryum__cpx 是否存在。

@akryum/cpx 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@akryum/cpx 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@akryum/cpx 可以商用吗?

@akryum/cpx 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@akryum/cpx 的下载量有多少?

根据 npm 官方下载统计,@akryum/cpx 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,698 次,日均约 57 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@akryum/cpx 还在维护吗?

最新版本 1.5.3 发布于 2021/07/30(5 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。