esbuild-plugin-copy-file

raw JSON →
0.0.2 verified Fri May 01 auth: no javascript

An esbuild plugin for copying files asynchronously and in parallel before and after bundling. Current stable version is 0.0.2. Released sporadically. It offers a simple configuration object mapping target to source paths for both pre- and post-bundle copies. Differentiates from other copy plugins by its minimal API and concurrency support.

error TypeError: copyFilePlugin is not a function
cause Using named import instead of default import.
fix
Change import { copyFilePlugin } to import copyFilePlugin.
error Error: ENOENT: no such file or directory, copyfile 'source.png' -> 'dest.png'
cause Provided source path does not exist or relative path resolved incorrectly.
fix
Ensure source file exists and paths are relative to the project root or use absolute paths.
gotcha The before and after options map target to source, not source to target. Confusing API design.
fix Use syntax { 'targetPath': 'sourcePath' } instead of { 'sourcePath': 'targetPath' }.
deprecated The plugin uses synchronous fs-extra internally? (Not confirmed, but concurrency may be misleading). Check implementation before relying on parallel behavior.
fix Use async/await at the build level if necessary.
npm install esbuild-plugin-copy-file
yarn add esbuild-plugin-copy-file
pnpm add esbuild-plugin-copy-file

Shows how to use esbuild-plugin-copy-file to copy a manifest file before bundling and a report file after bundling.

import esbuild from 'esbuild';
import copyFilePlugin from 'esbuild-plugin-copy-file';

await esbuild.build({
  entryPoints: ['./src/index.js'],
  outdir: './dist',
  bundle: true,
  plugins: [
    copyFilePlugin({
      before: {
        './dist/manifest.json': './src/manifest.json'
      },
      after: {
        './dist/report.json': './build-info/report.json'
      }
    })
  ]
});
console.log('Build complete');