Registry / devops / esbuild-plugin-copy-file

esbuild-plugin-copy-file

JSON →
library0.0.2jsnpmunverified

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.

npm install esbuild-plugin-copy-file
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-COP
E
esbuild-plugin-copy-file
devopsjavascriptv0.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (no named exports)
import copyFilePlugin from 'esbuild-plugin-copy-file';
import { copyFilePlugin } from 'esbuild-plugin-copy-file';
The package exports a single default function; named destructuring will result in undefined.
CommonJS require
const copyFilePlugin = require('esbuild-plugin-copy-file').default;
const copyFilePlugin = require('esbuild-plugin-copy-file');
Because the default export is transpiled to module.exports.default, direct require() returns an object with default property.
Configuration object
import copyFilePlugin from 'esbuild-plugin-copy-file'; const options = { before: { 'src.png': 'dest.png' }, after: { 'report.json': 'out/report.json' } };
const options = { before: { src: 'src.png', dest: 'dest.png' } };
The before and after options expect an object mapping target path to source path, not source to destination. The key is the target (where to copy to) and the value is the source (where to copy from). This is reversed from many other copy utilities.

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');
Debug
Known issues
gotchaThe before and after options map target to source, not source to target. Confusing API design.
fix
Use syntax { 'targetPath': 'sourcePath' } instead of { 'sourcePath': 'targetPath' }.
affects: >=0.0.1
deprecatedThe 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.
affects: 0.0.2
Errors
Common errors & fixes
TypeError: copyFilePlugin is not a function
Using named import instead of default import.
fix
Change `import { copyFilePlugin }` to `import copyFilePlugin`.
Error: ENOENT: no such file or directory, copyfile 'source.png' -> 'dest.png'
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.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
fs-extraoptionalused for file copy operations with async support
Agent activity
6 hits · last 30 days
node
6
Resources
esbuild-plugin-copy-file — npm install esbuild-plugin-copy-file · libregistry