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

Is it possible to retain folder structure in outputdir? #618

Closed
oze4 opened this issue Dec 23, 2020 · 5 comments
Closed

Is it possible to retain folder structure in outputdir? #618

oze4 opened this issue Dec 23, 2020 · 5 comments

Comments

@oze4
Copy link

oze4 commented Dec 23, 2020

Per the title...I am trying to retain the same structure in my output (so I suppose I just want to transpile/minify but not bundle into a single file), is this possible?

@oze4
Copy link
Author

oze4 commented Dec 23, 2020

Sorry to bother, I figured it out.

This was for a react project - I had to change esbuild ./src to esbuild ./src/**.

Full Command: esbuild ./src/** --outdir=./dist --loader:.js=jsx

@oze4 oze4 closed this as completed Dec 23, 2020
@devklick
Copy link

Is this still valid? I get an error when I try this.

Example structure:

src/
  lib/
    some-file.ts
  index.ts

Command:

esbuild ./src/** --outdir=./dist

Error:

Could not resolve "./src/lib"

Using esbuild v0.17.18

@evanw
Copy link
Owner

evanw commented May 13, 2023

I'm assuming your shell is expanding ./src/** into ./src/lib here. If that's the case, then that's a problem with your shell, not with esbuild. Shell expansion happens before esbuild runs so esbuild doesn't even see ./src/** at all. You'll need to read your shell's documentation to figure out how to do glob expansion correctly. Either that or you can pass all of the files to esbuild manually.

@devklick
Copy link

Thanks @evanw, I realised it must be something like that after seeing an error:

It looks like you are trying to use glob syntax (i.e. "*") with esbuild. This syntax is typically
handled by your shell, and isn't handled by esbuild itself. You must expand glob syntax first
before passing your paths to esbuild.

It appears to work if I specify file types, e.g.

esbuild ./src/**/*.ts --outdir=./dist

Offroaders123 added a commit to Offroaders123/NBTify that referenced this issue Feb 15, 2024
The more I look into this, the more complex it seems, and the less sure I am with both the way I have things now, as well as whether I like the other options instead.

I think I may just stick with TSC for compiling my package code in general, and if anything I can still do/try out the dual-build setup with ESM/CJS, but maybe just use TSC, since I can ensure that things are built consistently.

Should I provide synchronous APIs from NBTify? I think learning about how to work with async has really helped me progress, and I don't want to prevent someone else from learning that if I go with providing a sync option to my API. Or rather, if anything, that would only work in Node, because the Compression Streams API is only an asynchronous implementation. I'd have to use Node Zlib as a fallback to allow for a synchronous implementation, and it would be for Node only. I'm not sure I like the splintering of that either.

I think I have realized afterall, that I don't specifically want to use ESBuild for building my packages, since it's meant to bundle code, and I think I would only want to use that in a situation of building an ESM bundle for the browser. I may look into that as well though. Maybe I can use pkgbuild for that instead though? It kind of works a bit nicer for plain TS type generation support out of the box, as well as the configuation for things just plain working. Maybe I can look into making my own tool kind of like that, since it feels like all of the tools for this that I find, they all don't quite work exactly like how I want them to, unfortunately.

https://www.reddit.com/r/node/comments/14os7zv/the_esmcjs_situation/
https://github.com/wooorm/npm-esm-vs-cjs
https://stackoverflow.com/questions/46515764/how-can-i-use-async-await-at-the-top-level
https://stackoverflow.com/questions/71517624/because-i-cant-run-await-on-the-top-level-i-have-to-put-it-into-an-async-funct
https://commerce.nearform.com/blog/2021/node-esm-and-exports/
https://dev.to/a0viedo/nodejs-typescript-and-esm-it-doesnt-have-to-be-painful-438e
https://www.reddit.com/r/node/comments/14rg9ym/esm_not_gaining_traction_in_backend_node/
nodejs/node#49432
https://github.com/azu/tsconfig-to-dual-package
https://www.breakp.dev/blog/simple-library-package-setup-with-esbuild/
https://esbuild.github.io/api/#build
evanw/esbuild#263
evanw/esbuild#618
microsoft/TypeScript#46005

https://guitar.com/news/music-news/devin-townsend-shredding-dreams-steve-vai/
https://www.reddit.com/r/DevinTownsend/comments/17s332s/devin_and_the_vai_years/
https://www.reddit.com/r/DevinTownsend/comments/k9jot4/devin_townsend_i_was_unable_to_articulate_my/
https://www.kerrang.com/devin-townsend-i-was-unable-to-articulate-my-discontent-so-i-tended-to-act-up-i-even-took-a-sh-t-in-steve-vais-guitar-case
https://www.reddit.com/r/DevinTownsend/comments/6tia0r/is_vai_comparing_devin_to_zappa/
Offroaders123 added a commit to Offroaders123/NBTify that referenced this issue Feb 21, 2024
The more I look into this, the more complex it seems, and the less sure I am with both the way I have things now, as well as whether I like the other options instead.

I think I may just stick with TSC for compiling my package code in general, and if anything I can still do/try out the dual-build setup with ESM/CJS, but maybe just use TSC, since I can ensure that things are built consistently.

Should I provide synchronous APIs from NBTify? I think learning about how to work with async has really helped me progress, and I don't want to prevent someone else from learning that if I go with providing a sync option to my API. Or rather, if anything, that would only work in Node, because the Compression Streams API is only an asynchronous implementation. I'd have to use Node Zlib as a fallback to allow for a synchronous implementation, and it would be for Node only. I'm not sure I like the splintering of that either.

I think I have realized afterall, that I don't specifically want to use ESBuild for building my packages, since it's meant to bundle code, and I think I would only want to use that in a situation of building an ESM bundle for the browser. I may look into that as well though. Maybe I can use pkgbuild for that instead though? It kind of works a bit nicer for plain TS type generation support out of the box, as well as the configuation for things just plain working. Maybe I can look into making my own tool kind of like that, since it feels like all of the tools for this that I find, they all don't quite work exactly like how I want them to, unfortunately.

https://www.reddit.com/r/node/comments/14os7zv/the_esmcjs_situation/
https://github.com/wooorm/npm-esm-vs-cjs
https://stackoverflow.com/questions/46515764/how-can-i-use-async-await-at-the-top-level
https://stackoverflow.com/questions/71517624/because-i-cant-run-await-on-the-top-level-i-have-to-put-it-into-an-async-funct
https://commerce.nearform.com/blog/2021/node-esm-and-exports/
https://dev.to/a0viedo/nodejs-typescript-and-esm-it-doesnt-have-to-be-painful-438e
https://www.reddit.com/r/node/comments/14rg9ym/esm_not_gaining_traction_in_backend_node/
nodejs/node#49432
https://github.com/azu/tsconfig-to-dual-package
https://www.breakp.dev/blog/simple-library-package-setup-with-esbuild/
https://esbuild.github.io/api/#build
evanw/esbuild#263
evanw/esbuild#618
microsoft/TypeScript#46005

https://guitar.com/news/music-news/devin-townsend-shredding-dreams-steve-vai/
https://www.reddit.com/r/DevinTownsend/comments/17s332s/devin_and_the_vai_years/
https://www.reddit.com/r/DevinTownsend/comments/k9jot4/devin_townsend_i_was_unable_to_articulate_my/
https://www.kerrang.com/devin-townsend-i-was-unable-to-articulate-my-discontent-so-i-tended-to-act-up-i-even-took-a-sh-t-in-steve-vais-guitar-case
https://www.reddit.com/r/DevinTownsend/comments/6tia0r/is_vai_comparing_devin_to_zappa/
@rlindgren
Copy link

nice. but can we exclude some files by glob pattern that match the entry glob?

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

4 participants