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

How to skip transform javascript code? #674

Closed
hardfist opened this issue Jan 14, 2021 · 12 comments
Closed

How to skip transform javascript code? #674

hardfist opened this issue Jan 14, 2021 · 12 comments

Comments

@hardfist
Copy link
Contributor

hardfist commented Jan 14, 2021

we want to use esbuild as our build tools(which is super fast), But because our target is not browser and node( an embed Javascript runtime), which transform may break code , so I want to know is there any way to disable transform Javascript code when bundle, thanks。

@evanw
Copy link
Owner

evanw commented Jan 14, 2021

It's not currently possible to set the platform to something other than the browser or node. Can you say more about your use case? Which of esbuild's transforms are breaking your code, and how?

@hardfist
Copy link
Contributor Author

our build tools use two different javascript languages(for different purpose), one of which supports a subset of es3(JS-A), which most transform tools doesn't support, but we support esm by using rollup for now(because rollup doesn't do any transform by default, which meets our needs),and another js language(supports es5+,JS-B) use esbuild as our build tools, so we want also want to use esbuild instead of rollup to build the JS-A,but the transform result may break the code。

@evanw evanw closed this as completed in e8c2b62 Jan 18, 2021
@evanw
Copy link
Owner

evanw commented Jan 18, 2021

You can now specify --platform=neutral to disable esbuild's defaults. There is more information here: https://esbuild.github.io/api/#platform.

@hardfist
Copy link
Contributor Author

https://esbuild.github.io/api/#platform

It seems that even though I set platform neutral, It still do some transform(like transform let to var)

@SergeiMinaev
Copy link

SergeiMinaev commented Feb 28, 2021

Same here. I want to keep consts for example. Is there any way to bundle files without transpilation? I'd like to keep the code as is.

@evanw
Copy link
Owner

evanw commented Feb 28, 2021

I want to keep consts for example.

Why do you want to do this? Is it just for aesthetics? Whenever const is transformed to something else, esbuild makes assigning to a const symbol a build error so it should not be possible to bundle code that assigns to const and have it work at run time (in case that's what you are worried about).

It is intentionally not possible to keep top-level const symbols as const during bundling because some upcoming bundling features will require removing top-level const symbols to allow for lazy initialization of modules. In addition, changing top-level const and let to var improves the performance of your code. The const and let features introduce additional overhead compared to var because of checks for something called the "temporal dead zone." This is especially problematic for bundling because bundling creates a single extremely large top-level scope with lots of variables, and certain JavaScript VMs have a huge performance penalty (e.g. >5 additional seconds of initialization time) in this case if you use const and let instead of var.

@SergeiMinaev
Copy link

Is it just for aesthetics?

Yeah, it looks like this.

Whenever const is transformed to something else, esbuild makes assigning to a const symbol a build error so it should not be possible to bundle code that assigns to const and have it work at run time (in case that's what you are worried about).

Ok I got it.

This is especially problematic for bundling because bundling creates a single extremely large top-level scope with lots of variables, and certain JavaScript VMs have a huge performance penalty (e.g. >5 additional seconds of initialization time) in this case if you use const and let instead of var.

Wow, this is interesting. I should rethink the priorities. Thanks!

@hardfist
Copy link
Contributor Author

hardfist commented Mar 2, 2021

my case is very special, our javascript vm implementation does not support var,but support let, when esbuild transform let to var, it breaks our code

@evanw
Copy link
Owner

evanw commented Mar 3, 2021

my case is very special, our javascript vm implementation does not support var,but support let, when esbuild transform let to var, it breaks our code

That is interesting. However, I do not intend for esbuild to include logic for handling JavaScript language subsets like this. Various parts of esbuild's internals may produce var when bundling even independent of what your code looks like. This is because var is an older language feature than let, and it is assumed that older language features are safer to use than newer language features.

@hardfist
Copy link
Contributor Author

hardfist commented Mar 9, 2021

so esbuild's tranformer function is not opt-in but bound to it's other functionality?

@hardfist
Copy link
Contributor Author

@evanw , Except let | var | const things, can other transformer features be opt-out ? esbuild plugin is so much elegant than rollup when deal with virtual module, This is the last thing stop I migrate from rollup.

@therealparmesh
Copy link

therealparmesh commented Apr 14, 2022

We use SWC quite a bit, but we also love the bundling functionality that esbuild provides over Webpack. If we could optionally skip the transform step for esbuild given that we use an esbuild SWC plugin, that'd be a perfect setup for us. Is there any chance that such a proposed change would be accepted?

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

Successfully merging a pull request may close this issue.

4 participants