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

esbuild removes the folder structure when input is a single file with its path having uplevel folders. #4058

Open
jcyrss opened this issue Jan 30, 2025 · 3 comments

Comments

@jcyrss
Copy link

jcyrss commented Jan 30, 2025

Unzip this file,

sample.zip

If we input command to compile multiple files, like this

d:\tmp\sample>esbuild  share.jsx coms\toplevel.jsx  --outdir=./_build

  _build\share.js          147b
  _build\coms\toplevel.js  102b

⚡ Done in 3ms

You can see, for input file coms\toplevel.jsx, esbuild kept the parent folder coms in output.


But, if we input command to just compile a single file, like this

d:\tmp\sample>esbuild  coms\toplevel.jsx  --outdir=./_build

  _build\toplevel.js  102b

⚡ Done in 3ms

You can see, esbuild removed the parent folder coms in output.


I think esbuild should keep folder stucture when just compile a single file.

@jcyrss jcyrss changed the title esbuild removes the folder structure when input is a single file with its path having folders. esbuild removes the folder structure when input is a single file with its path having uplevel folders. Jan 30, 2025
@jcyrss
Copy link
Author

jcyrss commented Jan 30, 2025

This is a documented behavior: https://esbuild.github.io/api/#outdir:~:text=If%20your%20build%20contains%20multiple%20entry%20points%20in%20separate%20directories%2C%20the%20directory%20structure%20will%20be%20replicated%20into%20the%20output%20directory%20starting%20from%20the%20lowest%20common%20ancestor%20directory%20among%20all%20input%20entry%20point%20paths

so if we want keep the output file path structure as input file path, we have to specify it by --outfile?

Is there other more convenient switch to use like '--keep-folder-in-path'?

@jcyrss
Copy link
Author

jcyrss commented Feb 1, 2025

I found a workaround to keep output directory structure the same as multi-level-dir input file. That is to use --outbase=.

esbuild  coms\toplevel.jsx  --outdir=./_build --outbase=.
``

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