# copy-assets

> Copy assets with specific extensions, prefix, suffix

Latest version **1.0.3** (published 2020-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install copy-assets
pnpm add copy-assets
yarn add copy-assets
bun add copy-assets
```

Provides the command `copy-assets`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-12-16 |
| First published | 2019-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gautier Miquet |
| Maintainers | xisabla |
| Keywords | copy, assets, webpack, import, extension, prefix, suffix |

## Links

- npm: https://www.npmjs.com/package/copy-assets
- Repository: https://github.com/Xisabla/copy-assets
- Issues: https://github.com/Xisabla/copy-assets/issues
- npm.io page: https://npm.io/package/copy-assets

## Dependencies (1)

- [minimist](https://npm.io/package/minimist.md) ^1.2.5

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-12-16
- 1.0.2 — 2019-07-17
- 1.0.1 — 2019-07-17
- 1.0.0 — 2019-07-17

## README

# copy-assets

Copy assets with specific extensions, prefix, suffix or thanks to a regex

## Installation

```bash
npm i -g copy-assets

# or locally
npm i --save copy-assets

# then, you might do this
npm i --save-dev copy-assets
```

## Why ?

To be honest, I was bored to use gulp to copy files from my projects sources to the build folder so as to run webpack

I decided to make a command specially for this and then keeping the architecture of the sources but only copying the files I want

Going from this :

```text
|- dist - b - file1.js
\- src
    |- a - file1.png
    |- b - file1.ts
    \- c - file2.png
```

To that :

```text
|- dist - a - file1.png
|   |---- b - file1.js
|   \---- c - file2.png
|
\- src
    |- a - file1.png
    |- b - file1.ts
    \- c - file2.png
```

In one command

## Usage

### API

Basically, running a copy goes like this:

```js
const copy = require('copy-assets').default

copy({
    src: 'path_to_source',
    dist: 'path_to_destination',
    whitelist: [], // Array of filters,
    blacklist: [], // Array of filters,
    importWebpack: true,
    webpackConfig: 'webpack.dev.config.js',
    verbose: true
})
```

If any file match one of the whitelist filters AND none of the blacklist filers, then it will be copied from the source to the destination

The copy will look recursively for the files and then create the needed folders

Every field of the config is required, otherwise, it may crash.

#### Filter

A filter is an object with some optional fields: extension, prefix, suffix, regex, match

```js
let filter = {
  extensions: '.js', // or just 'js',
  prefix: 'prefix_',
  suffix: '_suffix',
  regex: new RegExp('^_anotherOne?'),
  match: function(filename, filepath) {
    return true
  }
}
```

A file should match every fields of a filter to be copied, then you can target only js files with prefix, or suffix, or use a custom matching function

### Cli

This is the purpose of that package, here is the usage:

```text
Usage: copy-assets <source> <destination> [options]

  Options:

    --help - Show this

    --ext=.js - Allow files with a specific suffix

    --exts=".js,.css,.cscc" - Same as --ext but works will multiple extensions at once, joined with a ","

    --prefix=dist_ - Allow files with a specific prefix

    --suffix=_dist - Allow files with a specific suffix

    --allowRegex="^prefix_" - Allow files matching regex

    --banRegex="^prefix_" - Ban files matching regex

    --importWebpack=webpack.config.js, -w webpack.config.js - Import extensions from webpack rules

    --verbose, v - Print out some info

    Note: Using !, * or other special selectors will not work, maybe it would one day

```

The most important thing is that you can import extensions from webpack rules automatically

## License

MIT

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