esbuild-plugin-mxn-copy
raw JSON → 1.0.1 verified Fri May 01 auth: no javascript
Esbuild plugin to copy assets (files and directories) into the output directory during bundling. Version 1.0.1 is stable with ~12.7kb size. Alternatives include @chialab/esbuild-plugin-copy (more configurable) and esbuild-plugin-copy (glob patterns). This plugin uses explicit from/to objects, supports verbose logging and a restrictive mode to limit directory access.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/esbuild-plugin-mxn-copy/index.js not supported. ↓
cause Using require() on an ESM-only package.
fix
Change to import statement: import esbuildMxnCopy from 'esbuild-plugin-mxn-copy'
error TypeError: esbuildMxnCopy is not a function ↓
cause Namespace import instead of default import.
fix
Use default import: import esbuildMxnCopy from 'esbuild-plugin-mxn-copy'
Warnings
gotcha Plugin does not support glob patterns; each copy entry must be an explicit path. ↓
fix Use array of {from, to} objects for each file or directory. For globs, consider alternatives like @chialab/esbuild-plugin-copy.
gotcha The 'to' path in copy entries is relative to the project root, not the outdir. Destination is exactly as specified. ↓
fix Ensure the 'to' path matches the desired output location; it does not automatically append to outdir.
breaking Package is ESM-only; requires Node.js >=12 or bundler that supports ESM. ↓
fix Use import syntax or dynamic import. For CommonJS projects, use import() or switch to a CommonJS-compatible copy plugin.
Install
npm install esbuild-plugin-mxn-copy yarn add esbuild-plugin-mxn-copy pnpm add esbuild-plugin-mxn-copy Imports
- default wrong
const esbuildMxnCopy = require('esbuild-plugin-mxn-copy')correctimport esbuildMxnCopy from 'esbuild-plugin-mxn-copy' - build wrong
const { build } = require('esbuild'); const esbuildMxnCopy = require('esbuild-plugin-mxn-copy')correctimport { build } from 'esbuild'; import esbuildMxnCopy from 'esbuild-plugin-mxn-copy'
Quickstart
import { build } from 'esbuild';
import esbuildMxnCopy from 'esbuild-plugin-mxn-copy';
build({
entryPoints: ['src/index.js'],
bundle: true,
outdir: 'dist',
plugins: [
esbuildMxnCopy({
copy: [
{ from: 'src/index.html', to: 'dist/index.html' },
{ from: 'src/logo.svg', to: 'dist/' },
{ from: 'src/preact', to: 'dist/preact' }
],
verbose: true
})
]
}).catch(() => process.exit(1));