Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to specify an output directory with esbuild-plugin-meta-url #135

Open
dhdaines opened this issue Mar 24, 2023 · 3 comments
Open

Unable to specify an output directory with esbuild-plugin-meta-url #135

dhdaines opened this issue Mar 24, 2023 · 3 comments

Comments

@dhdaines
Copy link

Hi! The esbuild-plugin-meta-url is quite useful when moving from webpack to esbuild. Unfortunately it seems to default to a behaviour of reproducing the relative path to the referenced files, and trying to recreate that path, where webpack would have renamed them (in some configurable fashion) and placed them in the output directory or a configurable assets directory.

The reason this is desireable is that, well, first, it avoids having weirdly long paths embedded in your bundle in the case where the files came from somewhere deep in node_modules, but second, if the files happen to come from somewhere outside the working directory (as will be the case when using npm link), the plugin will build a directory somewhere else, possibly a place you don't want it to, or where you don't even have write permission. For example, if you have index.js:

const img = new URL('../foo/logo.png', import.meta.url).href;
console.log(`URL is ${img}`);

and build.mjs:

import esbuild from 'esbuild';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';

await esbuild.build({
  entryPoints: ["index.js"],
  bundle: true,
  outdir: "dist",
  format: "esm",
  plugins: [
    metaUrlPlugin(),
  ],
});

Then, on running build.js, you will create these files:

$ node build.mjs 
$ find . -mmin -1
./dist/index.js
./foo/logo.png

That's probably not what you want. This may seem kind of contrived, but as mentioned earlier, it will happen in the case where you use npm link, and in any case it would be nice to be able to collect all your assets in a folder called, perhaps, dist/assets.

@edoardocavazza
Copy link
Member

Hello @dhdaines! Thanks for reporting!
Could you check if the latest version of the plugin correctly saves the file in the output directory?

@stale
Copy link

stale bot commented May 28, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label May 28, 2023
@dhdaines
Copy link
Author

Hi! Sorry for the very late reply! The latest version seemed to have the same behaviour when I tried it ... two months ago (sorry again) ... not sure if there has been another one since then? I will have some time today or tomorrow to recheck this.

@stale stale bot removed the wontfix This will not be worked on label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants