esbuild-plugin-copy
raw JSON → 2.1.1 verified Mon Apr 27 auth: no javascript
ESBuild plugin for copying assets during builds. Current stable version 2.1.1, released under the LinbuduLab organization. Supports glob patterns, keeps file structure, has watching mode based on chokidar polling, and allows flexible destination configuration. Differentiates from simple shell commands by integrating directly into ESBuild's plugin lifecycle, offering verbose logging, and the ability to copy only on asset changes.
Common errors
error No files matched using current glob pattern: ./node_modules/tinymce/skins/* ↓
cause Using 'dir/*' when there are no direct files in that directory, only subdirectories.
fix
Change glob pattern to './node_modules/tinymce/skins/**/*' to include files in subdirectories.
Warnings
gotcha Glob pattern 'dir/*' does not expand directories; use 'dir/**/*' to include nested files. ↓
fix Use 'from: ['./dir/**/*']' to match all files recursively.
gotcha Watching mode requires ESBuild's watch option to be enabled and only works for files outside absWorkingDir. ↓
fix Set 'watch: true' in both ESBuild build options and plugin options. Ensure watched files are not inside absWorkingDir.
deprecated The 'resolveFrom' option may change behavior in future versions; rely on ESBuild's outdir/outfile by default. ↓
fix Omit 'resolveFrom' to use ESBuild output directory as base path.
Install
npm install esbuild-plugin-copy yarn add esbuild-plugin-copy pnpm add esbuild-plugin-copy Imports
- copy wrong
import copy from 'esbuild-plugin-copy'correctimport { copy } from 'esbuild-plugin-copy'
Quickstart
import { build } from 'esbuild';
import { copy } from 'esbuild-plugin-copy';
(async () => {
const res = await build({
entryPoints: ['./src/main.ts'],
bundle: true,
watch: true,
outfile: './dist/main.js',
plugins: [
copy({
resolveFrom: 'cwd',
assets: {
from: ['./assets/*'],
to: ['./assets'],
},
watch: true,
}),
],
});
})();