-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Switch from ts-loader to babel-loader #2449
Conversation
I don't know who to address this to, so I try @gauravtiwari and @jakeNiemiec :-) Could this request be of interest? Otherwise I would close this and just continue to maintain my fork. |
Thanks @gopeter Apologies for the delay. Yes, definitely please keep it open. Will take a look at all open PRs this weekend. |
package/rules/typescript.js
Outdated
// Process application TypeScript code with Babel. | ||
// Uses application .babelrc to apply any transformations | ||
module.exports = { | ||
test: /\.(ts|tsx)?$/, |
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.
@gopeter Can we use the same babel loader to enable typescript as well?
https://github.com/rails/webpacker/blob/master/package/rules/babel.js#L8
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 would be possible if we add the ts/tsx extensions to it. But then Babel would be able to parse Typescript files, even without running webpacker:install:typescript
before – which is necessary to get the configuration files (like tsconfig.json). I think it would be better if we don‘t mix it up.
But: we may could add the ts/tsx extensions to the current Babel config in the Typescript install script. Then we could also remove the environment.loaders.delete('typescript')
step, which you mentioned below.
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 see, I think that's fine.
It wouldn't do anything for people who aren't using typescript but will probably fail if they are using typescript and don't have tsconfig.json? But perhaps not, since some of default options would on in the preset itself, 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.
Could you please test by including extensions as default?
@@ -1,3 +1,4 @@ | |||
const { environment } = require('@rails/webpacker') | |||
environment.loaders.delete('typescript') |
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.
Do we need to do this?
Hi @gauravtiwari. I've added the Users still have to run |
Awesome, thanks for working on it 🍰 |
Great! Thanks for merging! 😄 |
Hey, does this have a recommended upgrade path for existing TypeScript users who upgrade to 5.1? |
Not yet, I‘m going to make a new PR today with docs for it. Maybe we can also add a rake task for it? |
@noelrappin & @gauravtiwari I've created #2541. Sorry for not thinking about this before 😞 |
Using
ts-loader
has some drawbacks:babel-macros
withts-loader
(but it's already included inrails/webpacker
and therefore should work)@babel/preset-env
work, thets-loader
has to be combined withbabel-loader
, which means that we have to configure and manage multiple loaders (which may decrease build times)I'm not sure if it's good to add
package/rules/typescript.js
since it has the same content aspackage/rules/babel.js
. We could add.ts
and.tsx
directly to thebabel.js
loader, but then Webpacker would be able to compile.ts
and.tsx
files without runningwebpacker:install:typescript
before, which is essential to make it work correctly.Anyway, I'm not sure if the switch away from
ts-loader
is going to be merged, but with the current setup I can't usebabel-macros
together with TypeScript (likestyled-components/macro
andgraphql.macro
).