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

[UX] esbuild does not compile imported files #1513

Closed
205g0 opened this issue Aug 10, 2021 · 2 comments
Closed

[UX] esbuild does not compile imported files #1513

205g0 opened this issue Aug 10, 2021 · 2 comments

Comments

@205g0
Copy link

205g0 commented Aug 10, 2021

I guess I got this totally wrong:

Pls check https://github.com/205g0/strange and run pnpm i, then pnpm run dev, you only get index.ts compiled to index.js but not lib.ts in dist.

Once you add --bundle to package.json's dev script, lib is included/bundled into index.js. I understood from the docs that bundling brings some advantages even to the node side of things.

Ok, got that, but what do I do if I don't want to bundle? --splitting? Tried and got again no lib.ts compiled...

So, what do I miss?

@marvinhagemeister
Copy link

I understood from the docs that bundling brings some advantages even to the node side of things.

The main advantage of combining multiple files to one big one (=bundling) is that it reduces the amount of network requests if loaded in the browser or files to read from disk if loaded inside node. In node's case it probably only makes sense if one has enough files to warrant that optimization. Most projects don't fall into that category.

Ok, got that, but what do I do if I don't want to bundle? --splitting?

The --splitting argument enables what is commonly referred to as code splitting. The idea is that one big bundle of a web app usually contains code that is only used on certain pages. So there is no point in loading code for page B when we're on page A. Esbuild will therefore check for dynamic import statements like import('../page/B') and create a separate file that is only loaded once the import is called. Those files are usually named "chunks". But what if multiple pages use the same shared library? It would be wasteful to load the same library on page B and page C separately. So esbuild will try to move that into a shared chunk that both page B and C can use.

Tried and got again no lib.ts compiled...

What you're looking for is a way to transpile all files in a folder. That is something that is currently not supported out of the box by esbuild, as the main goal of esbuild is to be a bundler.

Instead you can use a quick bash or node script to collect all files you want to transpile and pass them to esbuild as seen in this comment.

But what you can do is use a quick bash or node script to collect all files you want to transpile and pass that list to esbuild.

@evanw
Copy link
Owner

evanw commented Dec 4, 2022

Closing this issue due to age, and because this request is already tracked by other open issues (e.g. #708).

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2022
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

3 participants