# @barusu/rollup-plugin-copy

> rollup plugins to copy files and folds (glob supported)

Latest version **0.0.47** (published 2021-02-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @barusu/rollup-plugin-copy
pnpm add @barusu/rollup-plugin-copy
yarn add @barusu/rollup-plugin-copy
bun add @barusu/rollup-plugin-copy
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.47 |
| Published | 2021-02-25 |
| First published | 2020-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 12.16.0 |
| Dependencies | 5 |
| Unpacked size | 22.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | guanghechen |
| Maintainers | lemonclown |
| Keywords | rollup, typescript |

## Links

- npm: https://www.npmjs.com/package/@barusu/rollup-plugin-copy
- Repository: https://github.com/guanghechen/barusu
- Homepage: https://github.com/guanghechen/barusu/tree/master/scaffolds/rollup-plugin-copy#readme
- Issues: https://github.com/guanghechen/barusu/issues
- npm.io page: https://npm.io/package/@barusu/rollup-plugin-copy

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [globby](https://npm.io/package/globby.md) ^11.0.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.0.1
- [@types/fs-extra](https://npm.io/package/@types/fs-extra.md) ^9.0.6
- [is-plain-object](https://npm.io/package/is-plain-object.md) ^5.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.47 (latest) — 2021-02-25
- 0.0.46 — 2021-02-24
- 0.0.45 — 2021-01-20
- 0.0.44 — 2020-12-29
- 0.0.43 — 2020-12-19
- 0.0.42 — 2020-12-19
- 0.0.41 — 2020-11-14
- 0.0.40 — 2020-10-21
- 0.0.39 — 2020-10-06
- 0.0.38 — 2020-09-28
- 0.0.37 — 2020-09-21
- 0.0.36 — 2020-09-20
- 0.0.35 — 2020-09-14
- 0.0.34 — 2020-09-09
- 0.0.33 — 2020-09-08
- … 14 more at https://npm.io/package/@barusu/rollup-plugin-copy/versions

## README

[![npm version](https://img.shields.io/npm/v/@barusu/rollup-plugin-copy.svg)](https://www.npmjs.com/package/@barusu/rollup-plugin-copy)
[![npm download](https://img.shields.io/npm/dm/@barusu/rollup-plugin-copy.svg)](https://www.npmjs.com/package/@barusu/rollup-plugin-copy)
[![npm license](https://img.shields.io/npm/l/@barusu/rollup-plugin-copy.svg)](https://www.npmjs.com/package/@barusu/rollup-plugin-copy)


This project is modified from https://github.com/vladshcherbin/rollup-plugin-copy.

A few months ago I submitted a [pr](https://github.com/vladshcherbin/rollup-plugin-copy/pull/42) that supports watch mode, but no response was received, so I decided to release it separately.


# Install

* Install
  ```shell
  yarn add --dev @barusu/rollup-plugin-copy
  ```

# Usage

```js
// rollup.config.js
import copy from '@barusu/rollup-plugin-copy'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/app.js',
    format: 'cjs'
  },
  plugins: [
    copy({
      targets: [
        { src: 'src/index.html', dest: 'dist/public' },
        { src: ['assets/fonts/arial.woff', 'assets/fonts/arial.woff2'], dest: 'dist/public/fonts' },
        { src: 'assets/images/**/*', dest: 'dist/public/images' }
      ]
    })
  ]
}
```

## Configuration

There are some useful options:

### targets

Type: `Array` | Default: `[]`

Array of targets to copy. A target is an object with properties:

- **src** (`string` `Array`): Path or glob of what to copy
- **dest** (`string` `Array`): One or more destinations where to copy
- **rename** (`string` `Function`): Change destination file or folder name
- **transform** (`Function`): Modify file contents

Each object should have **src** and **dest** properties, **rename** and **transform** are optional. [globby](https://github.com/sindresorhus/globby) is used inside, check it for [glob pattern](https://github.com/sindresorhus/globby#globbing-patterns) examples.

#### File

```js
copy({
  targets: [{ src: 'src/index.html', dest: 'dist/public' }]
})
```

#### Folder

```js
copy({
  targets: [{ src: 'assets/images', dest: 'dist/public' }]
})
```

#### Glob

```js
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }]
})
```

#### Glob: multiple items

```js
copy({
  targets: [{ src: ['src/index.html', 'src/styles.css', 'assets/images'], dest: 'dist/public' }]
})
```

#### Glob: negated patterns

```js
copy({
  targets: [{ src: ['assets/images/**/*', '!**/*.gif'], dest: 'dist/public/images' }]
})
```

#### Multiple targets

```js
copy({
  targets: [
    { src: 'src/index.html', dest: 'dist/public' },
    { src: 'assets/images/**/*', dest: 'dist/public/images' }
  ]
})
```

#### Multiple destinations

```js
copy({
  targets: [{ src: 'src/index.html', dest: ['dist/public', 'build/public'] }]
})
```

#### Rename with a string

```js
copy({
  targets: [{ src: 'src/app.html', dest: 'dist/public', rename: 'index.html' }]
})
```

#### Rename with a function

```js
copy({
  targets: [{
    src: 'assets/docs/*',
    dest: 'dist/public/docs',
    rename: (name, extension) => `${name}-v1.${extension}`
  }]
})
```

#### Transform file contents

```js
copy({
  targets: [{
    src: 'src/index.html',
    dest: 'dist/public',
    transform: (contents, srcPath, destPath) => (
      contents.toString()
        .replace('__SCRIPT__', 'app.js')
        .replace('__SOURCE_FILE_PATH__', srcPath)
        .replace('__TARGET_FILE_NAME__', path.basename(srcPath))
    )
  }]
})
```

### verbose

Type: `boolean` | Default: `false`

Output copied items to console.

```js
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  verbose: true
})
```

### hook

Type: `string` | Default: `buildEnd`

[Rollup hook](https://rollupjs.org/guide/en/#hooks) the plugin should use. By default, plugin runs when rollup has finished bundling, before bundle is written to disk.

```js
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  hook: 'writeBundle'
})
```

### watchHook

Type: `string` | Default: `buildStart`

[Rollup hook](https://rollupjs.org/guide/en/#hooks) the [this.addWatchFile](https://rollupjs.org/guide/en/#thisaddwatchfileid-string--void) should call. By default, `addWatchFile` called on each rollup.rollup build.
Only be used in hooks during the build phase, i.e. in `buildStart`, `load`, `resolveId`, and `transform`.

```js
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  watchHook: 'resolveId'
})
```


### copyOnce

Type: `boolean` | Default: `false`

Copy items once. Useful in watch mode.

```js
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  copyOnce: true
})
```

### flatten

Type: `boolean` | Default: `true`

Remove the directory structure of copied files.

```js
copy({
  targets: [{ src: 'assets/**/*', dest: 'dist/public' }],
  flatten: false
})
```

All other options are passed to packages, used inside:
  - [globby](https://github.com/sindresorhus/globby)
  - [fs-extra copy function](https://github.com/jprichardson/node-fs-extra/blob/7.0.0/docs/copy.md)

# Thanks Original Authors

  * [Cédric Meuter](https://github.com/meuter)
  * [vladshcherbin](https://github.com/vladshcherbin)

---
_Source: https://npm.io/package/@barusu/rollup-plugin-copy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
