npm package: @m00nbyte/rollup-plugin-copy-multiple-assets
Description: Copies files and directories from multiple sources to several destinations
Author: m00nbyte
Latest version: 1.0.0

# rollup-plugin-copy-multiple-assets

[![npm version](https://img.shields.io/npm/v/@m00nbyte/rollup-plugin-copy-multiple-assets.svg)](https://www.npmjs.org/package/@m00nbyte/rollup-plugin-copy-multiple-assets) [![npm downloads](https://img.shields.io/npm/dm/@m00nbyte/rollup-plugin-copy-multiple-assets)](https://www.npmjs.org/package/@m00nbyte/rollup-plugin-copy-multiple-assets)

---

## Features

-   Copy files and directories with full control
-   Multiple source and destination paths
-   Concurrent operations with configurable limits
-   Watch mode support for automatic re-copying
-   Preserve or flatten directory structures
-   Verbose logging options
-   Overwrite control for existing files
-   TypeScript support

## Installation

```bash
npm install -D @m00nbyte/rollup-plugin-copy-multiple-assets
yarn add -D @m00nbyte/rollup-plugin-copy-multiple-assets
```

## Usage

```js
// rollup.config.js
import copy from '@m00nbyte/rollup-plugin-copy-multiple-assets';

export default {
    plugins: [
        copy([
            {
                source: 'src/favicon.ico',
                destination: 'dist/favicon.ico'
            },
            {
                source: 'src/images',
                destination: 'dist/assets/images'
            },
            {
                source: ['README.md', 'LICENSE'],
                destination: ['dist', 'build']
            }
        ])
    ]
};
```

## Advanced Configuration

```js
// Using the options object format
export default {
    plugins: [
        copy({
            assets: [
                {
                    source: 'src/assets',
                    destination: ['dist/assets', 'public/assets']
                },
                {
                    source: ['src/fonts', 'src/icons'],
                    destination: 'dist/static'
                }
            ],
            verbose: true, // Enable detailed logging
            overwrite: true, // Overwrite existing files
            concurrency: 5, // Limit concurrent operations
            flatten: false // Preserve directory structure
        })
    ]
};
```

## API Reference

The plugin accepts either an array of assets or a configuration object:

#### Array Format (Simple)

```js
copy([{ source: 'src/file.txt', destination: 'dist/file.txt' }]);
```

#### Object Format (Advanced)

```js
copy({
    assets: [...],
    verbose: boolean,
    overwrite: boolean,
    concurrency: number,
    flatten: boolean
});
```

### Asset Object

| Property    | Type               | Required | Description                                       |
| ----------- | ------------------ | -------- | ------------------------------------------------- |
| source      | string \| string[] | Yes      | Single file/directory or array of sources to copy |
| destination | string \| string[] | Yes      | Single or multiple destination paths              |

### Options

| Option      | Type    | Default | Description                                                               |
| ----------- | ------- | ------- | ------------------------------------------------------------------------- |
| verbose     | boolean | true    | Enable detailed console output                                            |
| overwrite   | boolean | true    | Overwrite existing files at destination                                   |
| concurrency | number  | 10      | Maximum concurrent copy operations                                        |
| flatten     | boolean | false   | Copy files directly to destination without preserving directory structure |

## Error Handling

The plugin is designed to be resilient:

-   Missing source files are logged as warnings but don't stop the build
-   Copy failures are logged but allow other operations to continue
-   File permissions errors are caught and reported

## Best Practices

-   Use absolute paths for clarity when working with nested directories
-   Set appropriate concurrency based on your system capabilities (default 10)
-   Enable verbose logging during development, disable in production
-   Consider file size when setting concurrency for large files
-   Test flatten behavior with your specific directory structure

## Performance Tips

-   Higher concurrency values improve performance but use more system resources
-   Use flatten: true when you don't need directory structure (faster)
-   Copy entire directories instead of individual files when possible
-   Consider file size when setting concurrency limits

## Contribution

Feel free to submit issues or pull requests.

## Like my work?

This project needs a :star: from you.
Don't forget to leave a star.

<a href="https://www.buymeacoffee.com/m00nbyte" target="_blank">
    <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="217" height="60">
</a>

## [Changelog](CHANGELOG.md)

## [License](LICENSE)