Open borekb opened 5 years ago
Hey @borekb ,
IIRC, babel simply strips off all types and doesn't even read tsconfig.json
for that purpose - that means it does not know of typescript project references. Maybe you can use the --watch
option from babel cli to rebuild automatically?
Project references do not make sense, if used in combination with @babel/preset-typescript
and should be replaced by a custom build step - would be happy to to be corrected by someone, if there is still a reason left.
@borekb my understanding like @ford04 is that this is not supported by @babel/preset-typescript
. It would be a really sweet feature though 😄
The way I'm working around this atm is to add an npm script that runs a build watcher from the shared lib + the consuming app. e.g.
// package.json
{
"scripts: {
"dev": "concurrently \"cd packages/shared-lib && yarn build:watch\" \"cd packages/main-app && yarn start\""
}
}
// packages/main-app/package.json
{
// ...
"scripts: {
"start": "react-scripts start"
}
}
// packages/shared-lib/package.json
{
// ...
"scripts: {
"build:watch": "tsc -w"
}
}
/cc @RyanCavanaugh
Would it be hard to support this out-of-the-box?
And has anyone considered this (project references) together with yarn workspaces?
Thanks!
Edit:
I suppose one could currently use babel's project wide configuration and always run the type-check/build tasks from the top of the monorepo atm. Still, a first-class solution would be way better.
But as @ford04 says the main benefit of project references in a pure tsc
-built project is that you get up-to-date type checking against the public API of any referenced projects when you build an individual project. @babel/preset-typescript
does zero type checking, it knows nothing about your types, so building the types of referenced projects before the babel build gets you nowhere.
I would have thought the correct approach surely is to build your @babel/preset-typescript
as per normal in isolation, and then if you want to ensure you have no type errors then do a separate type-check step with tsc --noEmit
afterwards?
@jedrichards
<...> if you want to ensure you have no type errors then do a separate type-check step with
tsc --noEmit
afterwards?
what about type-checking custom features / proposals that babel supports with a plugin, but typescript does not?
It seems like there's no way to have both...
@sarpik Yeah true, tricky when you're using language features only Babel knows how to deal with 🤔
Let's say I have a monorepo with
packages/app
andpackages/lib
. In thetsc
world, I'd createapp/tsconfig.json
with this:And when transpiling,
tsc -b
would check if source files inlib
changed and re-build them if necessary.If Babel is responsible for transpiling, will it pick up changes in
lib
? Does it readtsconfig.json
configuration about project references?