# vite-plugin-static-copy

> rollup-plugin-copy for vite with dev server support.

Latest version **4.1.1** (published 2026-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-static-copy
pnpm add vite-plugin-static-copy
yarn add vite-plugin-static-copy
bun add vite-plugin-static-copy
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.1.1 |
| Published | 2026-06-06 |
| First published | 2021-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^22.0.0 \|\| >=24.0.0 |
| Dependencies | 4 |
| Unpacked size | 48.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 431 |
| Author | sapphi-red (https://github.com/sapphi-red) |
| Maintainers | sapphi-red |
| Keywords | vite, vite-plugin |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-static-copy
- Repository: https://github.com/sapphi-red/vite-plugin-static-copy
- Homepage: https://github.com/sapphi-red/vite-plugin-static-copy#readme
- Issues: https://github.com/sapphi-red/vite-plugin-static-copy/issues
- Funding: https://github.com/sponsors/sapphi-red
- npm.io page: https://npm.io/package/vite-plugin-static-copy

## Dependencies (4)

- [p-map](https://npm.io/package/p-map.md) ^7.0.4
- [chokidar](https://npm.io/package/chokidar.md) ^3.6.0
- [picocolors](https://npm.io/package/picocolors.md) ^1.1.1
- [tinyglobby](https://npm.io/package/tinyglobby.md) ^0.2.17

## 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

- 4.1.1 (latest) — 2026-06-06
- 4.1.0 — 2026-04-19
- 4.0.1 — 2026-04-04
- 4.0.0 — 2026-03-22
- 3.4.0 — 2026-03-22
- 3.3.0 — 2026-03-13
- 3.2.0 — 2026-01-27
- 3.1.6 — 2026-01-23
- 3.1.5 — 2026-01-19
- 3.1.4 — 2025-10-15
- 3.1.3 — 2025-10-01
- 2.3.2 — 2025-08-21
- 3.1.2 — 2025-08-21
- 3.1.1 — 2025-07-13
- 3.1.0 — 2025-06-25
- … 42 more at https://npm.io/package/vite-plugin-static-copy/versions

## README

# vite-plugin-static-copy

[![npm version](https://badge.fury.io/js/vite-plugin-static-copy.svg)](https://badge.fury.io/js/vite-plugin-static-copy) ![CI](https://github.com/sapphi-red/vite-plugin-static-copy/workflows/CI/badge.svg) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)

[`rollup-plugin-copy`](https://www.npmjs.com/package/rollup-plugin-copy) for Vite with dev server support.

> [!NOTE]
> Before you use this plugin, consider using [public directory](https://vitejs.dev/guide/assets.html#the-public-directory) or [`import` in JavaScript](https://vitejs.dev/guide/features.html#static-assets).
> In most cases, these will work.

## Install

```shell
npm i -D vite-plugin-static-copy # yarn add -D vite-plugin-static-copy
```

## Usage

Add `viteStaticCopy` plugin to `vite.config.js` / `vite.config.ts`.

```js
// vite.config.js / vite.config.ts
import { viteStaticCopy } from 'vite-plugin-static-copy'

export default {
  plugins: [
    viteStaticCopy({
      targets: [
        {
          src: 'bin/example.wasm',
          dest: 'wasm-files',
          rename: { stripBase: 1 }, // strips `bin/`
        },
      ],
    }),
  ],
}
```

For example, if you use the config above, you will be able to fetch `bin/example.wasm` with `fetch('/wasm-files/example.wasm')`.
So the file will be copied to `dist/wasm-files/example.wasm`.

> [!WARNING]
>
> If you are using Windows, make sure to use `normalizePath` after doing `path.resolve` or else.
> `\` is a escape charactor in `tinyglobby` and you should use `/`.
>
> ```js
> import { normalizePath } from 'vite'
> import path from 'node:path'
>
> normalizePath(path.resolve(__dirname, './foo')) // C:/project/foo
>
> // instead of
> path.resolve(__dirname, './foo') // C:\project\foo
> ```

### Options

See [options.ts](https://github.com/sapphi-red/vite-plugin-static-copy/blob/main/src/options.ts).

### Debug

You can enable detailed logging by setting the `DEBUG` environment variable:

```bash
DEBUG=vite:plugin-static-copy npm run dev
```

When debug logging is enabled, the plugin will output which file is served from each URL.

## Differences with `rollup-plugin-copy`

- Faster dev server start-up than using `rollup-plugin-copy` on `buildStart` hook.
  - Files are not copied and served directly from the server during dev to reduce start-up time.
- `dest` is relative to [`build.outDir`](https://vitejs.dev/config/build-options.html#build-outdir).
  - If you are going to copy files outside `build.outDir`, you could use `rollup-plugin-copy` instead. Because that does not require dev server support.
- [`tinyglobby`](https://www.npmjs.com/package/tinyglobby) is used instead of [`globby`](https://www.npmjs.com/package/globby).
  - Because `tinyglobby` is used inside `vite`.
- `transform` could return `null` as a way to tell the plugin not to copy the file, this is similar to the [CopyWebpackPlugin#filter](https://webpack.js.org/plugins/copy-webpack-plugin/#filter) option, but it expects `transform` to return the original content in case you want it to be copied.
- `transform` can optionally be an object, with a `handler` property (with the same signature of the `rollup-plugin-copy` transform option) and an `encoding` property (`BufferEncoding | 'buffer'`) that will be used to read the file content so that the `handler`'s content argument will reflect the correct encoding (could be Buffer);
- Directory structure is always preserved in the output (similar to `flatten: false` in `rollup-plugin-copy`). Use `rename: { stripBase: true }` for flat copy.

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