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

[Study] Rollup: replace plugin typescript by plugin swc #338

Closed
seedy opened this issue Apr 6, 2022 · 2 comments
Closed

[Study] Rollup: replace plugin typescript by plugin swc #338

seedy opened this issue Apr 6, 2022 · 2 comments
Labels
00-type/task area/infrastructure Pull requests that update infra/dependencies enhancement New feature or request

Comments

@seedy
Copy link
Contributor

seedy commented Apr 6, 2022

Description

https://github.com/mentaljam/rollup-plugin-swc

https://reactjsexample.com/use-swc-with-rollup-to-transform-esnext-and-typescript-code/

SWC is an extensible Rust-based platform for the next generation of fast developer tools. This plugin is designed to replace rollup-plugin-typescript2, @rollup/plugin-typescript, @rollup/plugin-babel and rollup-plugin-terser for you.

@seedy seedy added enhancement New feature or request area/infrastructure Pull requests that update infra/dependencies 00-type/task labels Apr 6, 2022
@paulocfjunior paulocfjunior self-assigned this Apr 7, 2022
@paulocfjunior
Copy link
Contributor

paulocfjunior commented Apr 8, 2022

Findings

Currently, when using swc for typescript projects, we are still required to run tsc to generate the .d.ts files. This is the most time-consuming part of the build (taking around 40 sec to finish). The swc compiler takes only half a second to finish.

ℹ️ Our current build structure takes 110 seconds to generate the dist folder.

swc is planning to generate the .d.ts files by itself as it's mentioned in this article (and this issue) which will allow users to get rid of tsc. It will also be able to bundle the files, so it may replace rollup itself.

On the other hand, the Typescript team seems to be aware that there's room to improve the tsc building/type-checking speed, they just don't seem to prioritize that right now, but there's a possibility that they do something about it in the future.

Test results

I was able to build the lib using swc + tsc.

Screen Shot 2022-04-08 at 01 03 21

The whole process took 45s.

Caveat

SWC doesn't seem to support Tree Shaking right now (detected by inspecting the .next dir of the target app), and it's a mandatory point to allow us to go forward on it, once we currently have this optimization.

According to the swc project it should be implemented (ref 1, ref 2 - via spack), but this package doesn't exist at this moment (IDK if existed already or if it's still to be done).

Conclusion

From here, we should:

  • Keep the current build structure (maybe just upgrade the libs used) and wait for swc to be ready to support Tree Shaking and generate .d.ts files.
  • Use combination of swc + tsc to have the build working 2,5x faster, having in mind that swc is under heavy development.

@paulocfjunior paulocfjunior removed their assignment Apr 11, 2022
@seedy
Copy link
Contributor Author

seedy commented Apr 15, 2022

Closing with conclusions validated

@seedy seedy closed this as completed Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00-type/task area/infrastructure Pull requests that update infra/dependencies enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants