Add support for babel transform in monorepos #8651
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you have a monorepos with the following setup:
app
depends oncomponent
app
andcomponent
need to be transpiled with BabeljsYou are currently limited to running Parceljs from a common parent folder with a shared Babeljs config.
However there are several cases where this might be undesirable. Especially if you have multiple application projects sharing the same development packages that are under continuous development.
This limitation doesn't exist when using Parceljs without requiring Babel transpile of development packages.
Background
I ran into this problem when using Parceljs in an Infernojs-project. When using Reactjs I could use this project structure. However, since Infernojs requires babel-plugin-inferno to create optimised transpiled code, Parceljs fails and transpiles the JSX-code of development packages to React.createElement calls.
The Problem
What happens is that Parceljs won't pass projectRoot to babel when the asset being transpiled is outside projectRoot. This causes babel to fail to pick up a babel config file and thus skipping whatever transpilation is required by that package.
The Solution
This PR checks if the asset to be transpiled is actually inside the project root. If not it checks for a package root (closest ancestor folder containing package.json) and passes this as current working directory to Babeljs. This allows babel to find the package specific babel config file and allows the asset to be transpiled properly.
Tests
I have implemented tests for .js, .jsx, .ts and .tsx based on the babel-custom integration test.