-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Run typescript sources through full babel transpiling pipeline #3369
Conversation
Deploy preview ready! Built with commit 9477ff8 |
Thanks for the PR! I think we'd really like to avoid full Babel processing in addition to running through the typescript compiler, since it's a lot of potentially extra work. In the case of async/await that should work with just the TS compiler I think we'd want to figure out why that isn't working before adding an additional solution |
@jquense I don't think that's possible. To make TS emit safe code you need to target |
I'll hijack this PR to list (and hopefully fix) everything that's broken in gatsby in re. typescript support if you don't mind? Re. #3274, @wedelgaard I've figured what's wrong with async/await and this PR won't fix them completely. Apparently babel transpiles async/await syntax into generators (that's es6 too) and uglify chokes up on those then. One way to fix it would be by using Re #3356, I've found the place in gatsby that mutes webpack errors and propagated them properly, so all the issues raised in #3356 are fixed now. Re I've misread the docs, apparently what it does is that it disables everything in typescript that compiles and verifies the code. So as of now the default version of As for switching |
After poking around yarn more I figured that the version issue is covered by yarnpkg/rfcs#68, thus the typescript starter can be fixed with: "dependencies": {
"@types/react": "^15.6.2", // existing dependency
...
},
"resolutions": {
"**/@types/react": "^15.6.2"
}, by forcing all the types to the same version. |
It seems that Add .babelrc having {
"plugins": ["transform-regenerator"]
} Import polyfill that implements generators in import 'babel-polyfill'; I've verified that it's enough to make async/await functional in runtime |
@jquense, @KyleAMathews anything else you want me to do so this could land? Typescript support is still broken. I can work on moving the pipeline over to |
yes bable with JUST this transform should be run before typescript, which is waht is happening now. then TS compiler is left to compile whatever is left |
@jquense webpack loaders are applied right-to-left, so it's first transpiled by TS, then babel runs its pass. |
... and if I swap the order to run babel first and then the ts pass, then babel (expectedly) chokes up on the typescript code. |
I didn't notice the direction of the loaders sorry :P I still not sure though how this addresses the problem. Either you run the source through babel first and it will choke on the TS or after TS and it will fail because the tagged templates are gone. It seems like the "correct" way to to fix this is to build a TS equivalent to the babel plugin here (using the ts compiler). This should be feasible? you don't need real code generation, just the location of the tags and a string replace after they are extracted. The other potential option is babel 7 which does have TS parsing support |
I think the best route is to use something akin to the Rationale: let TS emit the richest possible output ( This has an added benefit of having to deal only with babel polyfills as TS won't generate any library code in this case. |
config.loader(`typescript`, { | ||
test, | ||
loaders: [ | ||
`babel?${JSON.stringify({ plugins: [extractQueryPlugin] })}`, | ||
`babel?${JSON.stringify(babelConfig)}`, |
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.
rather then passing through the babel config can you stick the ts loader in front of the existing js loader in the chain. You can also "override" the js
loader and pass a function the gets the current one and alters it.
its not clean, but this will be much easier to do neatly in v2, and i don't think we want to add more surface area if we can avoid it, since its much harder to deprecate later
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 I do that then typescript becomes a hard dependency. I don't think that makes sense for most people using gatsby.
@farcaller can you profile this change a bit to see roughly how much slower this PR makes things? If it's not too much, I think it'd be fine. We're moving to Babel 7 with Gatsby v2 which will give us more options. |
@KyleAMathews it is marginally slower, but don't forget that I'm comparing a fast and totally broken config with a slower and actually functional one. I don't think this should be a case where a faster option wins—the current plugin doesn't do what it advertises and breaks the prod builds. |
Ok, sold :-) Better working than fast. Make it work, make it correct, make it fast. Let's revisit this in Gatsby v2 once we're on webpack 3. |
Thanks a lot guys! Those TypeScript issues were pretty serious and just now I updated Gatsby and looks like minification works fine.. |
Hiya @farcaller! 👋 This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here. Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! 💪💜 |
This partially fixes #3356, maybe #3274 (#3274 fails to be minified).
Open issues:
program
for tests, as it comes from gatsby-cli and I'm not familiar enough with the test framework to try mocking that out.UglifyJsPlugin.js
still fails to bubble up the error / break the build with an error.transpileOnly
seems to be broken badly and is only used in tests.