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.
Common errors
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.
Warnings
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.
Install
npm install esbuild-plugin-copy-file yarn add esbuild-plugin-copy-file pnpm add esbuild-plugin-copy-file Imports
- default (no named exports) wrong
import { copyFilePlugin } from 'esbuild-plugin-copy-file';correctimport copyFilePlugin from 'esbuild-plugin-copy-file'; - CommonJS require wrong
const copyFilePlugin = require('esbuild-plugin-copy-file');correctconst copyFilePlugin = require('esbuild-plugin-copy-file').default; - Configuration object wrong
const options = { before: { src: 'src.png', dest: 'dest.png' } };correctimport copyFilePlugin from 'esbuild-plugin-copy-file'; const options = { before: { 'src.png': 'dest.png' }, after: { 'report.json': 'out/report.json' } };
Quickstart
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');