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.

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'
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.
npm install esbuild-plugin-mxn-copy
yarn add esbuild-plugin-mxn-copy
pnpm add esbuild-plugin-mxn-copy

Creates an esbuild build script that copies HTML, SVG, and a directory into the output using the copy plugin.

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));