---
title: "@farmfe/js-plugin-copy"
locale: "en"
version: "current"
canonicalUrl: "https://farmfe.org/docs/plugins/official-plugins/js-copy"
publicationStatus: "prerelease"
---

<a id="farmfejs-plugin-copy"></a>
# @farmfe/js-plugin-copy


JavaScript plugin that copies files or globs at the end of a Farm build.


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/js-plugin-copy --save-dev
```


**yarn**

```javascript
yarn add @farmfe/js-plugin-copy --dev
```


**pnpm**

```javascript
pnpm add @farmfe/js-plugin-copy --save-dev
```



<a id="usage"></a>
## Usage


```ts
import { defineConfig } from "@farmfe/core";
import copy from "@farmfe/js-plugin-copy";

export default defineConfig({
  plugins: [
    copy({
      targets: [
        { src: "public/**/*", dest: "dist" },
      ],
      verbose: true,
    }),
  ],
});
```


<a id="options"></a>
## Options


- ` targets?: Target[] ` — copy targets. Defaults to ` [] `.
- ` copyOnce?: boolean ` — copy only once, useful in watch mode. Defaults to ` false `.
- ` copySync?: boolean ` — use synchronous copy operations. Defaults to ` false `.
- ` flatten?: boolean ` — remove source directory structure under ` dest `. Defaults to ` true `.
- ` verbose?: boolean ` — log copied files. Defaults to ` false `.


Each target supports:


- ` src: string | string[] ` — path or glob to copy.
- ` dest: string | string[] ` — destination directory or directories.
- ` rename?: string | ((name: string, extension: string, fullPath: string) => string) ` — rename copied files.
- ` transform?: (contents: Buffer, name: string) => string | Buffer | Uint8Array ` — replace file contents before writing. The implementation only allows ` transform ` for matched files; if a glob matches a directory, using ` transform ` throws because directories do not have file contents to rewrite.


Other plugin and target options are passed through to ` globby `; remaining plugin options are also passed to ` fs-extra ` copy/write calls.
