# @akryum/cpx 中文文档

规范地址：https://npmcn.com/package/%40akryum/cpx/

版本：1\.5\.3
npm 元数据更新时间：2022-04-04T12:31:18.167Z
中文译文更新时间：2026-11-09T23:10:36.469Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40akryum/cpx
原文对照：https://npmcn.com/package/%40akryum/cpx/?lang=original
项目主页：https://github.com/mysticatea/cpx
源码仓库：https://github.com/mysticatea/cpx

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：66.1 kB，20 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=12\.0
- 运行依赖：12 个
- 首次发布：2021-04-04T17:52:58.949Z
- 最新版本发布：2021-07-30T14:55:49.400Z
- 近 30 天下载量：1698（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

复制文件 globs, 监视更改 .

## 安装

```sh
npm install @akryum/cpx
```

也可以使用：`pnpm add @akryum/cpx`、`yarn add @akryum/cpx`、`bun add @akryum/cpx`

## README

# 密码

[![npm version](https://img.shields.io/npm/v/cpx.svg)](https://www.npmjs.com/package/cpx) [![Downloads/month](https://img.shields.io/npm/dm/cpx.svg)](http://www.npmtrends.com/cpx) [![Build Status](https://travis-ci.org/mysticatea/cpx.svg?branch=master)](https://travis-ci.org/mysticatea/cpx) [![codecov](https://codecov.io/gh/mysticatea/cpx/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/cpx) [![Dependency Status](https://david-dm.org/mysticatea/cpx.svg)](https://david-dm.org/mysticatea/cpx)

复制文件 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` 目录,保留文件树结构. 每次文件被更改时,请复制.

> 由于巴什会膨胀出"光"字,需要用"双引"来附加.

你们可以一起用 [浏览器](http://browserify.org/)。 。 。 .

```
$ 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

您可以使用这个模块作为节点模块.

```js
var cpx = require("cpx");
```

### cpx. 副本

```ts
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. 复制同步

```ts
cpx.copySync(source, dest, options)
cpx.copySync(source, dest)
```

同步函数 `cpx.copy`。 。 。 .

参数几乎与 `cpx.copy`。 。 。 . 不过 `options.transform` 不被支持.

### cpx.watch (英语)

```ts
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 发布](https://github.com/mysticatea/cpx/releases)

## 捐款

谢谢你的贡献!

### 错误报告或特性请求

请使用 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 是什么？

复制文件 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 和提交记录判断。

