esbuild-copy-plugin
raw JSON → 1.0.0 verified Fri May 01 auth: no javascript
A plugin for esbuild that copies files or directories from one location to another during the build process. Version 1.0.0 is the current release. It provides a simple API to define copy operations using `from` and `to` paths. Unlike general-purpose tools like `cpy` or `copy-webpack-plugin`, this is tightly integrated with esbuild's plugin system and runs as part of the build lifecycle. The package is lightweight, with no dependencies. It is maintained, but has a low release cadence.
Common errors
error Error: The plugin "copy" returned a copy result but the build finished. ↓
cause The copy operation completed after esbuild finished because it's asynchronous but not awaited.
fix
Make sure esbuild build is awaited (since esbuild 0.17+ build returns a promise).
error TypeError: copy is not a function ↓
cause Using `import { copy } from 'esbuild-copy-plugin'` instead of default import.
fix
Use
import copy from 'esbuild-copy-plugin' or const copy = require('esbuild-copy-plugin'). Warnings
gotcha The `from` path is relative to the current working directory, not the esbuild build's root. ↓
fix Use absolute paths or ensure your working directory is the project root.
gotcha The `to` path is relative to the output directory (outfile/outdir's parent by default). ↓
fix Specify 'to' relative to outdir, e.g., if outdir is './dist', to: '.' places files directly in './dist'.
deprecated No known deprecations. ↓
fix N/A
Install
npm install esbuild-copy-plugin yarn add esbuild-copy-plugin pnpm add esbuild-copy-plugin Imports
- default
import copy from 'esbuild-copy-plugin' - default wrong
const { copy } = require('esbuild-copy-plugin')correctconst copy = require('esbuild-copy-plugin')
Quickstart
import esbuild from 'esbuild';
import copy from 'esbuild-copy-plugin';
await esbuild.build({
entryPoints: ['./src/index.js'],
bundle: true,
outfile: './dist/index.js',
plugins: [
copy({ from: './public', to: '.' }),
],
});