-
- Notifications
You must be signed in to change notification settings - Fork 6.3k
feat(babel-plugin): use project's babel config to transpile dependencies #1282
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
Conversation
If we add a dependency to `transpileDependencies` list then it will not been transpiled by babel. This PR make it possible.
/cc @hzoo - what is the most idiomatic way in Babel 7 to force dependencies to be transpiled using the |
'openBrowser', | ||
'pluginResolution' | ||
'pluginResolution', | ||
'babelHelpers' |
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 don't see why this needs to be placed in cli-shared-utils
. It's used only by cli-plugin-babel
and should be placed in that package instead.
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.
because cli-plugin-typescript
also use babel-loader, may be in the future this will need there or some where else
const config = babelHelpers.loadUsersConfig(api.resolve('.')) | ||
| ||
// prevent from ignore | ||
config.ignore = [babelHelpers.resolveNodeModulesIgnorePattern(transpileDependencies)] |
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 not needed because we already have the exclude
rule above which applies babel-loader
only to the correct files.
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.
yes, you are right
filename: 'package.json' | ||
} | ||
| ||
const partial = babel.loadPartialConfig(options) |
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.
why use loadPartialConfig
then manually normalize instead of just using loadOptions
?
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.
loadPartialConfig
loads only users config(from: package.json, .babelrc, ...etc). both loadPartialConfig
and loadOptions
return not valid config for passing it to the babel-loader, this why there is need manually normilize config.
| ||
const options = { | ||
cwd: rootDir, | ||
filename: 'package.json' |
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 someone clarify what specifically this is meant to do? Babel's configuration can vary per-file, so by doing this you're essentially loading the subset of the configuration that happens to apply to this specific filename.
I'd be happy to help make things work more easily with Babel, but at the moment this all seems to be going against a bunch of Babel's expectations.
const config = babelHelpers.loadUsersConfig(api.resolve('.')) | ||
| ||
babelLoader | ||
.options(config) |
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.
How does babelLoader
here end up calling Babel exactly? I'd normally expect the loader to do all the work of reading the config, so I'm not totally following why this tries to read the config up front.
@loganfsmyth, @yyx990803 |
…al dependencies using nearest babel config in project's root for external dependencies
@yyx990803 @Hokid I'm sorry but I can't seem to understand how to make this work. How can I use this Thanks! |
If we add a dependency to
transpileDependencies
list then it will notbeen transpiled by babel. This PR make it possible.