-
Notifications
You must be signed in to change notification settings - Fork 394
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 support #731
Comments
This looks pretty impressive, but a major problem is that it does not support decorators, which would kind of go against how Nest does all of its DI. I'm definitely going to keep an eye on the library though. @kamilmysliwiec if this ever gets to a point where it could support Nest, what would you think? |
It seems that TS decorators might be supported at some point. Let's circle back when it's implemented. For now, |
have you tried @swc/core? they support decorators |
SWC has an issue with decorators |
|
This still doesn't support |
I think swc does work with nestjs now. Using the @swc/cli @swc/core packages and this .swcrc configuration
I run these commands and everything works fine. See this PR
|
Using either |
Can we use |
Sure, just depends on the scripts you set up and where you run the production build. You can absolutely use |
@dethereum Could you please tell me how to use |
For those who find this Issue, I created an example with |
@techvlad that esbuild plugin you use is using tsc to compile ts file with decorators. |
@axe-me I'm using https://github.com/anatine/esbuildnx/tree/main/packages/esbuild-decorators plugin, this plugin doesn't use |
I tried to get the solution of @techvlad running with TypeORM but had no luck unfortunately. |
@techvlad this one clearly using tsc to compile ts file with decorator inside, see: https://github.com/anatine/esbuildnx/blob/main/packages/esbuild-decorators/src/lib/esbuild-decorators.ts#L11 I just made a vitejs plugin to run my dev server with super fast HMR. it supports Nestjs out of box. However you have to set the tsCompiler to swc in order to make decorators works. |
@kamilmysliwiec |
As of right now, I don't believe we plan on changing out the If you'd like to implement your own build pipeline, it should be pretty doable with the combination of |
for swc users, this might be issue if you're using |
Hi all, I'm late for the party here. I've been working on For |
@nartc out of curiosity, only the decorators of |
Well, the Controller and stuff from NestJS works lol. My automapper's decorator also works. |
my workaround is always provide a default value export class CreateUserDto {
@IsEmail()
email: string = undefined as any;
} |
The problem is related to optional properties |
I can confirm that assigning a default value to each prop does indeed make it work (obviously this is less than ideal but it is something). |
Another option is to fix it on the Here is the patch I've got at the end, it's for
And surely get subscribed to swc-project/swc#2117 to know when this is fixed from |
This has been fixed by swc swc-project/swc#3459 🚀 |
It should be possible to use decorators with esbuild, right ? |
The |
You're damn right :-/ @jmcdo29 |
But you can just compile using the plugin I built. It will use tsc for the files which contain decorators and esbuild for everything else. It's still A LOT quicker. (https://github.com/thomaschaaf/esbuild-plugin-tsc) |
@thomaschaaf I believe 90% of files in Nest codebases will contain decorators. Could you share some benchmarks? 🙌 |
I’m curious why not just use swc if you want speed up? What’s the benefit choose esbuild? |
I am trying to evaluate the possibilites for using swc with nestjs. Currently, it looks very promising, since swc support https://github.com/manuschillerdev/nestjs-swc Since I am not the most experience nestjs developer - what would be the edge cases to test here? TLDR;
Might write something on dev.to about the experiment, if someone is interested? Demo: Updating a repository plus hot reloading the server is around 30-50ms, but may sometimes need longer. Sometimes Screen.Recording.2022-02-20.at.14.28.22.mov |
Thanks @manuschillerdev! I think the most substantial caveat is that CLI plugins ( |
ah I see - thanks @kamilmysliwiec |
When build with swc, there seems to be a problem with DI for property decorators. |
I've made this issue #1549 in order to track SWC support specifically, since ESBuild looks like a dead end in the medium term due to not supporting |
I have been using SWC to compile Nest recently and it seems to be working (all my code is managed in an Nx monorepo and we are using the @nrwl/js plugin with the swc compiler for buildable libraries) |
@yharaskrik are you using CLI plugins like swagger? |
Ah, I'm actually only using it to compile e2e tests. Our deployed code with swagger is still using the regular builders no swc. We are only using swc to compile plain node libs right now in deployed code. |
I'd just like to chime in here and say that I have been using Here is my {
"module": {
"type": "es6"
},
"jsc": {
"baseUrl": ".",
"target": "es2020",
"parser": {
"syntax": "typescript",
"decorators": true,
"importMeta": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true,
}
} I mostly was forced to go with a solution like |
@Nickersoft did you find a way to be able to use the CLI plugin? I've been using vite + swc pretty alright but the right way of enabling that functionality has eluded me |
esbuild version 0.18.5 was just released. This version supports decorators. Is support to building with esbuild still being considered? |
@gerardolima This looks to just be for the new JS decorator syntax, which Nest doesn't use. WE still use "legacy" decorators from Typescript because we need the emitted metadata that Typescript providers. If you're looking for a faster compilation cycle, Nest supports SWC in version 10 directly with the |
Feature Request
Add support for esbuild as the build system.
Is your feature request related to a problem? Please describe.
Building modules on large project takes sizeable amount of time, which makes debugging a bit slow. esbuild can potentially increase the build speed up to 86 times.
Describe the solution you'd like
Include esbuild into the list of supported build systems.
Teachability, Documentation, Adoption, Migration Strategy
esbuild repo
What is the motivation / use case for changing the behavior?
Speed. Speed. Speed.
The text was updated successfully, but these errors were encountered: