-
Notifications
You must be signed in to change notification settings - Fork 6
Replace TypeScript, Babel & terser with swc #203
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
base: main
Are you sure you want to change the base?
Conversation
| pragma: jsx?.pragma, | ||
| pragmaFrag: jsx?.fragment | ||
|
|
||
| // TODO: Improve JSX Handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want, we can add the 'modern' JSX option (automatic import) here as well. We could also address #144 if we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good - though of course it needs serious real-world testing.
The fact that so few changes are required makes me kinda suspicious - though it might just prove that we found the right abstractions? Only time will tell; see above.
lib/bundle/config.js
Outdated
| plugins = plugins.concat(determineCompacting(compact)); | ||
| } | ||
| if(compact === true || compact === "compact") { | ||
| plugins = plugins.concat(require("rollup-plugin-cleanup")()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is leaky now; we don't want to spread this kinda awareness across both config.js and swc.js.
generateSWCConfig might return both the config object and a list of plugins to be added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, true 🤔 So generateSWCConfig would not only handle SWC, but also plugin-cleanup, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think so, yes; seems like sensible encapsulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it out, but this leads to the following effects:
- We need to push down the generation of the swc plugin to the generateSWCConfig file
- The generateSWCConfig needs to check if it should even add the swc plugin
Overall, I don't really like it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of those seem like advantages to me rather than disadvantages. 🤷
My argument boils down to deletability: If we ever replace SWC again (which, given this very PR, doesn't seem improbable), we'd most likely have to revisit these three lines as well; that doesn't seem obvious to me at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I thought about it again and found a way that should appease us both. Take a look at the new commits starting from de16c9d
Also, remove duplicated defaults
Also, simplify the extensions logic
655e79c to
f6f714d
Compare

After experimenting with esbuild in #149, I wanted to try out the other new "transpiler" swc. That's the one used by Deno and Parcel. Note that this PR does not replace rollup, it uses swc for transpilation ('esnext', TypeScript & JSX) and minification. swc bundling is still under development, and I think it is too early for us.
My impression is very positive. The generated code is very similar to what we have right now, but in the places where it is different, I prefer the output to the one from Babel (for example the way it compiles
class).Notes:
rollup-plugin-cleanupforcompact=trueandcompact="compact".cjs, we deprecated it, as we usecommonjsinstead.