Registry /
devops / esbuild-plugin-copy-file
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');
Errors
Common errors & fixes
TypeError: copyFilePlugin is not a function
Using named import instead of default import.
fixChange `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.
fixEnsure source file exists and paths are relative to the project root or use absolute paths.
Audit
Dependencies
fs-extraoptionalused for file copy operations with async support