跳到主要内容
FarmFarm
Version: 2.x(最新)
本页目录

@farmfe/js-plugin-copy

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

Installation

javascript
npm install @farmfe/js-plugin-copy --save-dev
javascript
yarn add @farmfe/js-plugin-copy --dev
javascript
pnpm add @farmfe/js-plugin-copy --save-dev

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,
    }),
  ],
});

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.

100%

Drag or pinch to explore. Keyboard: + / − zoom, arrows pan, 0 resets, Esc closes.