LinbuduLab / esbuild-plugins

ESBuild plugins by @LinbuduLab
MIT License
113 stars 18 forks source link

[esbuild-plugin-copy] Copy `to` path not working as expected #86

Closed theo-staizen closed 1 year ago

theo-staizen commented 1 year ago

I am trying to copy some assets files from an npm package into ./dist/assets

import { build } from 'esbuild';
import { copy } from 'esbuild-plugin-copy';

await build({
  entryPoints: ['./src/index.ts'],
  bundle: true,
  format: 'esm',
  outfile: './dist/index.js',
  plugins: [
    copy({
      verbose: true,
      resolveFrom: 'out',
      assets: [
        {
          from: './node_modules/some-package/dist/esm/*.worker*.js',
          to: './assets/' // still copies files into ./dist
        }
      ]
    })
  ],
}).catch(() => process.exit(1));

Instead of copying to ./dist/assets it copies to ./dist. Here is the verbose output:

i Resolve assert pair to path from: /Users/.../esbuild/dist

i Use Merge-Structure for current assets pair.
i File copied: /Users/.../dist/esm/format.worker-28fe4aab.js -> /Users/.../esbuild/dist/format.worker-28fe4aab.js
i File copied: /Users/.../dist/esm/format.worker-51010d22.js -> /Users/.../esbuild/dist/format.worker-51010d22.js

If I try to use to: './dist/assets' it copies to ./dist/dist instead.

i Resolve assert pair to path from: /Users/.../esbuild/dist

i Use Merge-Structure for current assets pair.
i File copied: /Users/.../dist/esm/format.worker-28fe4aab.js -> /Users/.../esbuild/dist/dist/format.worker-28fe4aab.js
i File copied: /Users/.../dist/esm/format.worker-51010d22.js -> /Users/.../esbuild/dist/dist/format.worker-51010d22.js

I have no idea what's happening...

linbudu599 commented 1 year ago

Maybe you should use to: './assets' instead of to: './assets/'?

powerc9000 commented 1 year ago

This still happens for me without a trailing slash.