LinbuduLab / esbuild-plugins

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

Copy fails after first from #105

Open joeworkman opened 1 year ago

joeworkman commented 1 year ago

I have a very simple setup with copy. I just want to copy 2 files into a folder.

copy({
    assets: {
        from: [
            "node_modules/jquery/dist/jquery.min.js",
            "node_modules/what-input/dist/what-input.min.js"
        ],
        to: [ "js/vendor" ]
    },
})

However, it always fails when processing the 2nd file. If I switch the order of the files, it still fails on the 2nd one. I did a verbose output and got this.

i Resolve assert pair to path from: /Users/joeworkman/Developer/proton-sites-template/dist/assets
i Watching mode disabled. You need to enable build.watch option for watch mode to work.
i The from path node_modules/jquery/dist/jquery.min.js,node_modules/what-input/dist/what-input.min.js of current asset pair doesnot ends with /**/*(.ext), 
i File copied: /Users/joeworkman/Developer/proton-sites-template/node_modules/jquery/dist/jquery.min.js -> /Users/joeworkman/Developer/proton-sites-template/dist/assets/js/vendor/jquery.min.js
i The from path node_modules/jquery/dist/jquery.min.js,node_modules/what-input/dist/what-input.min.js of current asset pair doesnot ends with /**/*(.ext), 
ERR > /Users/joeworkman/Developer/proton-sites-template/node_modules/esbuild/lib/main.js:1649
  let error = new Error(text);
              ^
joeworkman commented 1 year ago

This works but it seems a bit ridiculous that I should have to do this.

        copy({ assets: {
            from : "node_modules/jquery/dist/jquery.min.js",
            to   : "js/vendor"
        }}),
        copy({ assets: {
            from : "node_modules/what-input/dist/what-input.min.js",
            to   : "js/vendor"
        }}),
abiencourt commented 2 months ago

@joeworkman a little cleaner approach (avoids to call twice the plugin)

const esbuildConfig = {
  plugins: [
    copy({
      assets: [
        {
          from: ["node_modules/jquery/dist/jquery.min.js"],
          to: ["js/vendor"],
        },
        {
          from: ["node_modules/what-input/dist/what-input.min.js"],
          to: ["js/vendor"],
        },
      ],
    }),
  ],
};